Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload a file to SharePoint through the built-in web services

Tags:

sharepoint

wss

What is the best way to upload a file to a Document Library on a SharePoint server through the built-in web services that version WSS 3.0 exposes?

Following the two initial answers...

  • We definitely need to use the Web Service layer as we will be making these calls from remote client applications.

  • The WebDAV method would work for us, but we would prefer to be consistent with the web service integration method.

There is additionally a web service to upload files, painful but works all the time.

Are you referring to the “Copy” service? We have been successful with this service’s CopyIntoItems method. Would this be the recommended way to upload a file to Document Libraries using only the WSS web service API?

I have posted our code as a suggested answer.

like image 257
Andy McCluggage Avatar asked Aug 28 '08 08:08

Andy McCluggage


People also ask

How do you upload a file in SharePoint library using REST API and jQuery?

In this articleConvert the local file to an array buffer by using the FileReader API, which requires HTML5 support. The jQuery(document). ready function checks for FileReader API support in the browser. Add the file to the Shared Documents folder by using the Add method on the folder's file collection.

Can SharePoint automatically upload documents?

SharePoint has several methods to upload files from Windows Explorer to a document library, but if you want to do it automatically, you should use a PowerShell script.


1 Answers

Example of using the WSS "Copy" Web service to upload a document to a library...

public static void UploadFile2007(string destinationUrl, byte[] fileData) {     // List of desination Urls, Just one in this example.     string[] destinationUrls = { Uri.EscapeUriString(destinationUrl) };      // Empty Field Information. This can be populated but not for this example.     SharePoint2007CopyService.FieldInformation information = new          SharePoint2007CopyService.FieldInformation();     SharePoint2007CopyService.FieldInformation[] info = { information };      // To receive the result Xml.     SharePoint2007CopyService.CopyResult[] result;      // Create the Copy web service instance configured from the web.config file.     SharePoint2007CopyService.CopySoapClient     CopyService2007 = new CopySoapClient("CopySoap");     CopyService2007.ClientCredentials.Windows.ClientCredential =          CredentialCache.DefaultNetworkCredentials;     CopyService2007.ClientCredentials.Windows.AllowedImpersonationLevel =          System.Security.Principal.TokenImpersonationLevel.Delegation;      CopyService2007.CopyIntoItems(destinationUrl, destinationUrls, info, fileData, out result);      if (result[0].ErrorCode != SharePoint2007CopyService.CopyErrorCode.Success)     {         // ...     } } 
like image 95
Andy McCluggage Avatar answered Sep 27 '22 20:09

Andy McCluggage