开发者

How can I upload a file to a Sharepoint Document Library using Silverlight and client web-services?

开发者 https://www.devze.com 2022-12-22 08:08 出处:网络
Most of the solutions I\'ve come across for Sharepoint doc library uploads use the HTTP \"PUT\" method, but I\'m having trouble finding a way to do this in Silverlight because it has restrictions on t

Most of the solutions I've come across for Sharepoint doc library uploads use the HTTP "PUT" method, but I'm having trouble finding a way to do this in Silverlight because it has restrictions on the HTTP Methods. I visited this http://msdn.microsoft.com/en-us/library/dd920295(VS.95).aspx to see how to allow PUT in my code, but I can't find how that helps you use an HTTP "PUT".

I am using client web-services, so that limits some of the Sharepoint 开发者_开发技巧functions available.

That leaves me with these questions:

  1. Can I do an http PUT in Silverlight?
  2. If I can't or there is another better way to upload a file, what is it?

Thanks


Figured it out!! works like a charm

    public void UploadFile(String fileName, byte[] file)
    {
        // format the destination URL

        string[] destinationUrls = {"http://qa.sp.dca/sites/silverlight/Answers/"+fileName}; 

        // 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 =fileName, 
             InternalName =fileName, 
             Type = SharepointCopy.FieldType.Text, 
             Value =fileName};

        // to specify the content type

        SharepointCopy.FieldInformation ctInformation = new SharepointCopy.FieldInformation
            {DisplayName ="XML Answer Doc", 
             InternalName ="ContentType", 
             Type = SharepointCopy.
             FieldType.Text, 
             Value ="xml"};

        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, file);
    }

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


What type of SharePoint deployment and what version of silverlight? If say it is an intranet deployment you could use UNC paths to access your document library in sharepoint and the savefiledialog/openfiledialog available in Silverlight 3.

http://progproblems.blogspot.com/2009/11/saveread-file-from-silverlight-30-in.html

or

http://www.kirupa.com/blend_silverlight/saving_file_locally_pg1.htm

Silverlight has restrictions on what it can do with local files, though I've read that silverlight 4 has some changes.

http://www.wintellect.com/CS/blogs/jprosise/archive/2009/12/16/silverlight-4-s-new-local-file-system-support.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消