none
Downloading a document from a sharepoint site to local file system, copy web service returns null

    Question

  • Hi Guys,
                   I am trying to get this done for the last 2 days and I am still banging my head to the wall.
    All I need to do is to download files from my sharepoint site library that uses integrated windows authentication. I was using copy webservice : getItem method to accomplish this.

    CopyService.GetItem(copySource, out myFieldInfoArray, out myByteArray);

    Problem : myByteArray is always returned as NULL

    Note: I have tried the same with another site that uses forms authentication but the result was the same (NULL !!)


    This is my code:

    CopyService.

    Copy copy = new CopyService.Copy();

     

    "https://mysharepointsite.com.au/it/dc/_vti_bin/copy.asmx";

     

    true;

     

    // Define the variables that will store the output from the web service call

    CopyService.

    FieldInformation fieldInfo = new CopyService.FieldInformation();

     

    FieldInformation[] fieldInfoArray = { fieldInfo };

     

    byte[] myByteArray = new Byte[] {};

     

     

    // Call the web service

     

    try

    {

     

    uint myGetUint = copy.GetItem(https://mysharepointsite.com.au/it/dc/documents/testdoc.txt, out fieldInfoArray, out myByteArray);

     

    catch (Exception ex)

     

    string message = ex.Message;

    }


    Any help is greatly appreciated.

    Cheers,
    Nick

     

    Update:
    I just came to know that the copy web service doesn't work for downloading list attachments and no out of the box web service does this. The copy web service only works for the documents within a document library

     

     

     

     

     

     

     

     

    CopyService.

     

    copy.UseDefaultCredentials =

    copy.Url =

    Monday, December 21, 2009 11:50 PM

Answers

  • You can use the lists web service GetAttachmentCollection to get the attachement. The following code uses the ID of the list item that has the attachement that you are looking for. The url of the attachment is returned in the inner text of the XmlNode and you can use this with the WebClient class and the DownloadData to retrieve the byte array


     public static void GetAttachements()
     {       
    
                listservice.Lists listProxy = new listservice.Lists();
    
                listProxy.Url = "http://basesmcdev2/sites/tester1/_vti_bin/lists.asmx";
                listProxy.UseDefaultCredentials = true;
    
                XmlNode retNode = listProxy.GetAttachmentCollection("myattachments2", "4");
    
                using (WebClient wc = new WebClient())
                {
                    wc.UseDefaultCredentials = true;
                    byte[] response = wc.DownloadData(retNode.InnerText);
                }
               
    }

    certdev.com
    • Proposed as answer by Rohit Puranik Friday, December 25, 2009 11:21 AM
    • Marked as answer by Mike Walsh FIN Friday, December 25, 2009 6:53 PM
    Tuesday, December 22, 2009 2:11 AM

All replies

  • You can use the lists web service GetAttachmentCollection to get the attachement. The following code uses the ID of the list item that has the attachement that you are looking for. The url of the attachment is returned in the inner text of the XmlNode and you can use this with the WebClient class and the DownloadData to retrieve the byte array


     public static void GetAttachements()
     {       
    
                listservice.Lists listProxy = new listservice.Lists();
    
                listProxy.Url = "http://basesmcdev2/sites/tester1/_vti_bin/lists.asmx";
                listProxy.UseDefaultCredentials = true;
    
                XmlNode retNode = listProxy.GetAttachmentCollection("myattachments2", "4");
    
                using (WebClient wc = new WebClient())
                {
                    wc.UseDefaultCredentials = true;
                    byte[] response = wc.DownloadData(retNode.InnerText);
                }
               
    }

    certdev.com
    • Proposed as answer by Rohit Puranik Friday, December 25, 2009 11:21 AM
    • Marked as answer by Mike Walsh FIN Friday, December 25, 2009 6:53 PM
    Tuesday, December 22, 2009 2:11 AM
  • Hello Steve.Curran

    Really this code is helpful for me. Thank you very much ... :)
    Friday, December 25, 2009 11:23 AM
  • Hi Steve,

    I found this very helpful but I'm receiving an error. 

    I was using the GetAttachmentCollection like you have written here but I have two attachments within the retNode.InnerText.  When the debugger reaches wc.DownloadData(retNode.InnerText) I get an error "The remote server returned an error: (500)Internal Server Error" because it doesn't know how to separate the two URLs inside the InnerText. 

    Do you know how to fix that?  Thank you for your help.


    C# Developer
    Friday, September 24, 2010 8:11 PM
  • Hi I need to save this returned file on my disk .. Can you please help me for that. Thanks

    Varun Verma

    Wednesday, September 11, 2013 11:59 AM
  • hi, 

    thanks for sharing.  but i can not do this code in visual studio for windows 8 store appalication.

    because there is no option to "add web reference" in vs for windows. there is only "add service reference".

    i add the asmx  by "add service reference" i get errors from your codes, while when i do the same code for "vs for desktop" it works perfectly, because in   "vs for desktop" i can "add web reference".

    any help or idea? please, i need it urgently

    Friday, August 29, 2014 10:58 AM