I'm using C# in Visual Studio with a Silverlight app. I want to upload a file to a document library, but none of the web-services here http://msdn.microsoft.com/en-us/library/ms479390.aspx seem to have a way to do this.

I'm not using object model, only service references to the .asmx's in that link.

2 Answers 2


After searching for a solution to this all week I finally found a web-service call that works with it. Here is how I solved this problem: (SharepointCopy is my service reference to copy.asmx)

   public void UploadFile(String fileName, byte[] file)

        string[] destinationUrls = {"http://[server]/sites/[listName]/"+fileName}; 

        // load the file into a file stream

        byte[] fileBytes = file;

        // fill out the metadata
        // remark: don't set the Name field, because this is the name of the document

        SharepointCopy.FieldInformation titleInformation = new SharepointCopy.FieldInformation
            {DisplayName ="Title", 
             InternalName ="Title", 
             Type = SharepointCopy.FieldType.Text, 
             Value ="Test1Title"};

        // to specify the content type

        SharepointCopy.FieldInformation ctInformation = new   SharepointCopy.FieldInformation
            {DisplayName ="Content Type", 
             InternalName ="ContentType", 
             Type = SharepointCopy.
             Value ="Your content type"};

        SharepointCopy.FieldInformation[] metadata = { titleInformation }; 

        // initialize the web service

        SharepointCopy.CopySoapClient copyws = new SharepointCopy.CopySoapClient(); 

        // execute the CopyIntoItems method
        copyws.CopyIntoItemsCompleted += copyws_CopyIntoItemsCompleted;
        copyws.CopyIntoItemsAsync("http://null", destinationUrls, metadata, fileBytes);


Many Thanks to Karine Bosch for the solution here: http://social.msdn.microsoft.com/Forums/en/sharepointdevelopment/thread/f135aaa2-3345-483f-ade4-e4fd597d50d4

  • 1
    this answer shows code snippet that never uses variable ctInformation. Jan 5, 2015 at 16:44

Uploading a document can be done using a HTTP PUT command, for example using WebClient and the UploadData method.

  • I know, but I don't know how to do an HTTP PUT in silverlight because silverlight limits http messages to GET and POST by default. How can I allow PUT calls?
    – Anonymous
    Mar 11, 2010 at 16:12
  • 1
    Are you sure about this. You have access to the WebClient class in SL so an UploadData(address, "PUT", bytes); would work? See msdn.microsoft.com/en-us/library/cc838250(VS.95).aspx Mar 11, 2010 at 16:40
  • I know it says you can there...my question in the first comment was how do I enable it? In SL UploadData is not available (at least by default). It only has UploadStringAsync for the WebClient
    – Anonymous
    Mar 11, 2010 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.