SharePoint 2010 Rest API: How to add attachment to a list item via ListData.svc

Hi
I have set up a project using the REST API in c# Visual Studio 2010.
I have added a service reference to the URL //site/_vti_bin/listdata.svc/
I can query the list and get back data, but I can't retrieve the attachments.
I can write data to the list, but I can't add attachments.
Are there any examples of how to add or retrieve attachments using the REST API services.
Thanks
Mike

Hi,                                                             
If you want to work with list attachments using REST API, here are some links will show how to do this using Javascript:
http://msdn.microsoft.com/en-us/library/office/dn292553.aspx#FileAttachments
http://chuvash.eu/2013/02/20/rest-api-add-a-plain-text-file-as-an-attachment-to-a-list-item/
http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2013/06/27/how-to-get-list-item-attachments-using-rest-and-javascript-in-sharepoint-2013.aspx
Best regards
Patrick Liang
TechNet Community Support

Similar Messages

  • How to add Gap between dropdown List Items - ComboBox in MFC VC++

    How to add Gap between dropdown List Items - ComboBox in MFC VC++

    Did you tried SetItemHeight() inside your App .
    Thanks
    Rupesh Shukla

  • Tutorial on how to update list items using ListData.svc

    Can you please point me to a tutorial which shows how to update a list item using listdata.svc and C#?
    Sorry if this is FAQ.
    I have found articles on read list... but I haven't found anything on update a list item.
    val it: unit=()

    when i try this I get an error 500
    I created an ASP.NET web application that allows the user to modify data that is stored in SharePoint I rather not go into the reasons why this application was created but focus more on why doesn't the listdata.svc allow me to update a task item that was
    created by a workflow collect data from user action.
    1. The workflow creates the item.
    I collect the item and update the item using the below code. This is not an OOTB approval workflow that is just the name I used. When I get to save changes I received the following error code.
    Dim getApprovalItem As ExpenseApprovalRuleBasedTasksItem = spContext.ExpenseApprovalRuleBasedTasks.Where(Function(i) i.Id = Pam.ApprovalItemID).FirstOrDefault
    If String.IsNullOrEmpty(getApprovalItem.AuditorApprovalValue) Then
    getApprovalItem.AuditingComments = approvalComments
    Select Case approvalDecision
    Case "Approved"
    getApprovalItem.AuditorApproval = ExpenseApprovalRuleBasedTasksAuditorApprovalValue.CreateExpenseApprovalRuleBasedTasksAuditorApprovalValue("Approved")
    getApprovalItem.AuditorApprovalValue = "Approved"
    Case "Rejected"
    getApprovalItem.AuditorApproval = ExpenseApprovalRuleBasedTasksAuditorApprovalValue.CreateExpenseApprovalRuleBasedTasksAuditorApprovalValue("Rejected")
    getApprovalItem.AuditorApprovalValue = "Rejected"
    End Select
    getApprovalItem.Outcome = "Completed"
    getApprovalItem.Status = ExpenseApprovalRuleBasedTasksStatusValue.CreateExpenseApprovalRuleBasedTasksStatusValue("Completed")
    getApprovalItem.StatusValue = "Completed"
    getApprovalItem.Complete = True
    spContext.UpdateObject(getApprovalItem)
    spContext.SaveChanges()
    End If

  • SharePoint 2010 REST API, User SiteColumn not coming

    When Create User sitecolumn from front end(using default SharePoint Setting area) and then fetch list through REST API then it comes parfactly but
    When I create User sitecolumn's xml from Visual Studio and then add that sitecolumn in contenttype and then in list and then fact list through REST API then it does come in api xml.

    Hi Manish<o:p></o:p>
     <o:p></o:p>
    I can understand your issue, but not sure what could be the reason behind this behavior. To help you resolve the issue, we will need troubleshooting to be done at your end. I would request you
    to open a support ticket with Microsoft to help us resolve your issue as quickly as possible.
    For more information about Microsoft Support please read the article http://support.microsoft.com/gp/proffaq/en-gb
     <o:p></o:p>
    Thanks,
    Bharat Rathod, <u1:p></u1:p><o:p></o:p>
    Microsoft Online Community Support<u1:p></u1:p><o:p></o:p>

  • APIM REST API - How to add an API with operations?

    When I issue a PUT to /apis/{aid} with import=true and contentType = application/json, I get an 400 BadRequest if the body contains operations.  Note that I'm
    not using WADL or Swagger format, and am building the JSON request body instead as per the documentation.  
    The error returned in the response body is:
    {"error":{"code":"ValidationError","message":"One or more fields contain incorrect values:","details":[{"code":"ValidationError","target":"operations","message":"Invalid
    field 'operations' specified"}]}}
    If I omit the operations field from the request body, the API is created correctly (but with no operations of course).  
    To illustrate, here is the RAW request (slightly modified to remove the authorization and instance names):
    PUT https://testinstance.management.azure-api.net/apis/123456?api-version=2014-02-14-preview&import=true HTTP/1.1
    Authorization: SharedAccessSignature . . .
    Content-Type: application/json; charset=utf-8
    Host: testinstance.management.azure-api.net
    Content-Length: 414
    Expect: 100-continue
    Connection: Keep-Alive
    {"name":"Customer","description":"This API is used to manage customers","serviceUrl":"http://www.somewebsite.com/customers","path":"customers","protocols":["http","https"],"operations":[{"id":"/apis/123456/operations/a04b16da-29b7-44f5-95a3-25603dbc9b6d","name":"Customer
    (Get)","description":"Returns information about the customer with the specified ID.","method":"GET","urlTemplate":"/customers/{customerId}"}]}
    The JSON looks correct to me - can anyone spot what I'm doing wrong?  Can you provide a RAW request that works?
    Note also that I've not included the "path" query string parameter, even though the documentation suggests that it is required when import=true.  Since there is no easy way to update APIs/Operations en masse, I'm having to resort to driving
    the APIM REST API and could use some additional documentation for this specific operation.

    Just updating this thread with the answer...my request body was malformed - I was using an array of objects for the operations field instead of a complex object representing the collection.
    So instead of this:
    "operations": [
    ...I should have been using this:
    "operations": {
        "value": [
    You can see the correctly formatted payload in the sample response body returned from the
    GetApi endpoint.
    Thanks to Vlad for pointing out my mistake!

  • SharePoint 2013 Rest API - How to get the item count with startsWith

    Hi All,
    I am using the below url to get the item count for specfied startsWith. For example I want to know how many items are there in the list which starts with "A". When i hit the below url in the address bar i am getting HTTP not found.
    siteURL/sites/Apps/SharePointApp3/_vti_bin/listdata.svc/SampleList/items?$filter=startsWith(Title,’A’)
    Navaneeth

    what
    is SharePointApp3.
    here. 
    it is a webpart.
    this will not work on webpart\apps
    Also I am not sure if it will work with specific SampleList 
    Try 
    siteURL/sites/Apps/SharePointApp3/SampleList/_vti_bin/listdata.svc/Keywords?$filter=substringof('r',Title)
    If this helped you resolve your issue, please mark it Answered

  • SharePoint Designer 2013 (2010 Platform Workflow) - How can I create a new list item with a SPECIFIC content type?

    In SharePoint 2010 I created workflows that used the 'Create list Item' Action, which then set the Content Type ID (so I could create documents of various types in a document library). 
    We just switched to the SharePoint 2013 platform, and now the drop down for Content Type ID is blank in all of the workflows that are still using the SharePoint 2010 platform.  Is there any way to create a list item with specific content
    type?  Even if I could just input a string into that field instead of using this blank drop-down.  Please help! 

    Hi Sarah,
    According to your description, my understanding is that you cannot create a new list item with a specific content type using SharePoint 2010 Platform Workflow.
    I tested the same scenario in my environment, and the Create List Item worked fine with the specific content type.
    How did you create the content type?
    Please check if the content type is added to the list/library the workflow associated with.
    Best regards.
    Thanks
    Victoria Xia
    TechNet Community Support

  • SharePoint 2013 Rest Api - How to get List Items

     
    Can anyone let me know why the below method fails? I am not getting where i am making mistake. Please help
    function getListItems(term) {
                var caml = "<View><Query><Where><BeginsWith><FieldRef Name=Title/><Value Type='Text'>" + term + "</Value></BeginsWith></Where></Query></View>";
                var requestData = { "query": { "__metadata": { "type": "SP.CamlQuery" }, "ViewXml": caml } };
                $.ajax({
                    url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/getbytitle('SampleList')/Getitems",
                    method: "POST",
                    data:requestData,
                    headers: {
                        "accept": "application/json; odata=verbose",
                        "content-type": "application/json; odata=verbose"
                    success: function (data) {
                        $("#countItem").html("Pass");
                    error: function (data) {
                        $("#countItem").html("Fail");
    Below is the responseText (log)
    "{\"error\":{\"code\":\"-1, Microsoft.SharePoint.Client.ClientServiceException\",\"message\":{\"lang\":\"en-US\",\"value\":\"The HTTP method \'GET\' cannot be used to access
    the resource \'GetItems\'. The operation type of the resource is specified as \'Default\'. Please use correct HTTP method to invoke the resource.\"}}}"
    Navaneeth

    Finally executed successfully using below code. The learning is we need to use  type:"POST" instead of method:"POST"
     function getListItems(term) {
                var urltest = _spPageContextInfo.webAbsoluteUrl + "/_api/Web/lists/getByTitle('SampleList')/getitems(<Query><Where><BeginsWith><FieldRef">query=@v1)?@v1={\"ViewXml\":\"<View><Query><Where><BeginsWith><FieldRef
    Name='Title'/><Value Type='Text'>" + term + "</Value></BeginsWith></Where></Query><RowLimit>1</RowLimit></View>\"}";
                $.ajax({
                    url: urltest,
                    type: "POST",
                    headers: {
                        "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                        "Accept": "application/json; odata=verbose",
                        "Content-Type": "application/json; odata=verbose"
                    contentType: 'application/json',
                    success: function (data) {
                        if (data.d.results.length != 1) {
                            $("#countItem").html("Pass");
                            $("#" + term).parent().parent().prop('disabled', true);
                            $("#" + term).removeAttr("onclick");
                            $("#" + term).css('cursor', 'default');
                            $("#" + term).parent().unbind("mouseenter mouseleave");
                    error: function (data) {
                        $("#countItem").html(urltest);
    Navaneeth

  • How to add values in a List item using code

    Hi all,
    I want to populate a list item at run time with the values of my choice.
    im using this
    add_list_element('list34',1, 'Name','Smith');
    or
    add_list_element('list34',1, 'Name',:emp.txtname);
    where emp is my data block and txtname is a text field on this emp block.
    noen of them is working, whether i try adding a string or the value in a text item.
    please help.

    It gives any error or just does nothing?
    Have you tried making another simple form with just one block and one or two items?
    You can do this type of testing in these conditions.
    Which version of forms are you using?

  • Im using CloverETL to connec to SharePoint using REST API.

    my team is trying to get the List items in SharePoint using REST api. we are using the CloverETL tool using the REST api URL of the list and the credentials in SharePoint which has full control. Below is the rest command that we used.
    /_api/web/lists/getbytitle('title of list')/items 
    when viewing this URL on the same Internet explorer with a user log on to sharepoint the XML of the list is successfully showing. but when we try to load it on the CloverETL tool using the same SharePoint credentials it says access is denied. Also when viewing
    the URL to a browser with no other SharePoint sites open it also says access is denied. 

    how is the webapp configured, as far as authentication?
    Scott Brickey
    MCTS, MCPD, MCITP
    www.sbrickey.com
    Strategic Data Systems - for all your SharePoint needs

  • Sharepoint angulr REST API update file item userd field property

    Hi All,
    I'm working on a project using SharePoint with angular to upload files to document library, for now every thins is working fine and good but when updating the related item fields I was using JSOM its work but it increase the version # of the file which is
    not acceptable to the client I found a solution to update the fields using REST without increasing the version # but the problem am facing now updating a user field it does not take the value it go to the success function but the field not set
    here's my code
     $scope.updateMetadataNoVersion=function(fileUrl) {
        var fld=$scope.SelectedFolder.replace(_spPageContextInfo.siteAbsoluteUrl, "");
           var restSource ="";
            if(fld.replace("lists/DepartmentDocuments","")=="")
           restSource = currentWeb.get_url() + "/_api/web/lists/getbytitle('DepartmentDocuments')/rootfolder/files/getbyurl(url='" + fileUrl + "')/listitemallfields/validateupdatelistitem";
    else
           restSource =  currentWeb.get_url() + "/_api/web/getfolderbyserverrelativeurl('"+fld+"')/files/getbyurl(url='" + fileUrl + "')/listitemallfields/validateupdatelistitem";
            var dfd = $.Deferred();
            $.ajax(
                'url': restSource,
                'method': 'POST',
                 'data': JSON.stringify({
                    'formValues': [
                        '__metadata': { 'type': 'SP.ListItemFormUpdateValue' },
                        'FieldName': 'ShareWith',
                        'FieldValue': '24'
                    'bNewDocumentUpdate': true,
                    'checkInComment': ''
                'headers': {
                    'accept': 'application/json;odata=verbose',
                    'content-type': 'application/json;odata=verbose',
                    'X-RequestDigest': $('#__REQUESTDIGEST').val()
                'success': function (data) {
                    var d = data;
                    dfd.resolve(d);
                'error': function (err) {
                    dfd.reject(err);
                    console.log(err);
            return dfd.promise;
    any help please im search about this since 3 days with no success
    Thanx in advance
    khatib7

    Yes, your correct. The validateupdatelistitem method does not work with Lookup values. You will have to use the standard way of updating the list item via REST but it will increment the version. I agree with you that many customers want to upload files and
    set data without creating 2 versions.  This is how SharePoint upload works. However, the only way to do this with REST is to use the validateupdatelistitem method.
    You can make a request for this to be added to SharePoint at User Voice:
    http://officespdev.uservoice.com/
    Blog | SharePoint Field Notes Dev Tools |
    SPFastDeploy | SPRemoteAPIExplorer

  • Sharepoint 2013 REST API calls with JASONP support

    We are working on sharepoint online integration with PHP Based application. We need to provide REST API call which supports JSONP.
    So is it possible to create new REST API Endpoints in Sharepoint online APP? Please sugggest right direction.

    Hi,
    In Office 365 (aka SharePoint Online), you can simply consume the SharePoint data through REST API or WS call,but cannot create your own endpoint.
    By default you can get the JSON response from the Office 365 REST API,its upto you to use the JSONP on your client compatibility not on SharePoint online REST API.
    Sometime before I tried, It didn't work for me.
    If you develop the AppModel, SPRequestor.js does the same job(overcome the Cross domain restriction) the what JSONP does.
    Murugesa Pandian| MCPD | MCTS |SharePoint 2010

  • How to add attachment in the background .

    Hi Experts,
    How can we add attachments to a document in the background .
    Example : how to add attachement to a purchase order  in background.
    Thanks in advance .
    Naval bhatt

    check out this weblog
    /people/rammanohar.tiwari/blog/2006/03/25/generic-object-services-gos--in-background--part-ii

  • How to implement tooltip for the list items for the particular column in sharepoint 2013

    Hi,
    I had created a list, How to implement tooltip for the list items for the particular column in SharePoint 2013.
    Any help will be appreciated

    We can use JavaScript or JQuery to show the tooltips. Refer to the following similar thread.
    http://social.technet.microsoft.com/forums/en/sharepointdevelopmentprevious/thread/1dac3ae0-c9ce-419d-b6dd-08dd48284324
    http://stackoverflow.com/questions/3366515/small-description-window-on-mouse-hover-on-hyperlink
    http://spjsblog.com/2012/02/12/list-view-preview-item-on-hover-sharepoint-2010/

  • How to add a video play list on palm pre

    Does anybody knows how to add a video play list in palm pre?
    I did try to add video in different folders but in the palm  device are loaded in the same playlist. Is there a way to organize video files?
    tks
    Post relates to: Pre p100ueu (O2)

    QuickTime requires player and plugins that most people don't have.  You'll reach a much wider audience if you use HTML5 <video> with mp4, webm and ogg files.
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>HTML5 with Video</title>
    <!--help for older IE browsers-->
    <!--[if lt IE 9]>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    </head>
    <style>
    video {
        max-width:100%;
        display:block;
        margin:0 auto;
    </style>
    <body>
    <h2>Use 3 File Types to support all browsers &amp; mobile devices:  MP4, WEBM and OGV.</h2>
    <h3>Online Video Converter
    http://video.online-convert.com/</h3>
    <!--begin video-->
    <video controls poster="Your_poster_image.jpg">
    <!--these are 6 sec sample videos for testing purposes. Replace sample-videos with your own files-->
    <source src="http://techslides.com/demos/sample-videos/small.webm" type="video/webm">
    <source src="http://techslides.com/demos/sample-videos/small.ogv" type="video/ogg">
    <source src="http://techslides.com/demos/sample-videos/small.mp4" type="video/mp4">
    If you're seeing this, you're using an
    outdated browser that doesn't support
    the video tag. </video>
    <!--end video-->
    </body>
    </html>
    Nancy O.

Maybe you are looking for