Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

Thanks for any help/suggestions you can offer

share|improve this question

2 Answers 2

up vote 5 down vote accepted

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.
             FieldType.Choice, 
             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

share|improve this answer

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

share|improve this answer
    
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 '10 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 –  Wictor Wilen MCA MCM MVP Mar 11 '10 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 '10 at 17:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.