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

拜拜、爱过 提交于 2019-12-21 06:28:36

问题


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


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/2419951/how-can-i-upload-a-file-to-a-sharepoint-document-library-using-silverlight-and-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!