<p>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?</p>

<p><strong>Following the two initial answers...</strong></p>

<ul>
<li><p>We definitely need to use the Web Service layer as we will be making these calls from remote client applications.</p></li>
<li><p>The WebDAV method would work for us, but we would prefer to be consistent with the web service integration method.</p></li>
</ul>

<p><Blockquote>
There is additionally a web service to upload files, painful but works all the time.
</Blockquote></p>

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

<p>I have posted our code as a suggested answer.</p>

[{'answer_id': 32499, 'author': 'Ben Scheirman', 'author_id': 3381, 'author_profile': 'https://Stackoverflow.com/users/3381', 'pm_score': 1, 'selected': False, 'text': '<p>From a colleage at work:</p>\n<blockquote>\n<p>Lazy way: your Windows WebDAV filesystem interface. It is bad as a programmatic solution because it relies on the WindowsClient service running on your OS, and also only works on websites running on port 80. Map a drive to the document library and get with the file copying.</p>\n<p>There is additionally a web service to upload files, painful but works all the time.</p>\n<p>I believe you are able to upload files via the FrontPage API but I don’t know of anyone who actually uses it.</p>\n</blockquote>\n'}, {'answer_id': 33585, 'author': 'Daniel O', 'author_id': 697, 'author_profile': 'https://Stackoverflow.com/users/697', 'pm_score': 1, 'selected': False, 'text': '<p>Not sure on exactly which web service to use, but if you are in a position where you can use the SharePoint .NET API Dlls, then using the SPList and SPLibrary.Items.Add is really easy.</p>\n'}, {'answer_id': 34274, 'author': 'Andy McCluggage', 'author_id': 3362, 'author_profile': 'https://Stackoverflow.com/users/3362', 'pm_score': 5, 'selected': True, 'text': '<p>Example of using the WSS "Copy" Web service to upload a document to a library...</p>\n\n<pre><code>public static void UploadFile2007(string destinationUrl, byte[] fileData)\n{\n    // List of desination Urls, Just one in this example.\n    string[] destinationUrls = { Uri.EscapeUriString(destinationUrl) };\n\n    // Empty Field Information. This can be populated but not for this example.\n    SharePoint2007CopyService.FieldInformation information = new \n        SharePoint2007CopyService.FieldInformation();\n    SharePoint2007CopyService.FieldInformation[] info = { information };\n\n    // To receive the result Xml.\n    SharePoint2007CopyService.CopyResult[] result;\n\n    // Create the Copy web service instance configured from the web.config file.\n    SharePoint2007CopyService.CopySoapClient\n    CopyService2007 = new CopySoapClient("CopySoap");\n    CopyService2007.ClientCredentials.Windows.ClientCredential = \n        CredentialCache.DefaultNetworkCredentials;\n    CopyService2007.ClientCredentials.Windows.AllowedImpersonationLevel = \n        System.Security.Principal.TokenImpersonationLevel.Delegation;\n\n    CopyService2007.CopyIntoItems(destinationUrl, destinationUrls, info, fileData, out result);\n\n    if (result[0].ErrorCode != SharePoint2007CopyService.CopyErrorCode.Success)\n    {\n        // ...\n    }\n}\n</code></pre>\n'}, {'answer_id': 35593, 'author': 'Eugene Katz', 'author_id': 1533, 'author_profile': 'https://Stackoverflow.com/users/1533', 'pm_score': 2, 'selected': False, 'text': '<p>I\'ve had good luck using the DocLibHelper wrapper class described here: <a href="http://geek.hubkey.com/2007/10/upload-file-to-sharepoint-document.html" rel="nofollow noreferrer">http://geek.hubkey.com/2007/10/upload-file-to-sharepoint-document.html</a></p>\n'}, {'answer_id': 44915, 'author': 'Jim Harte', 'author_id': 4544, 'author_profile': 'https://Stackoverflow.com/users/4544', 'pm_score': 3, 'selected': False, 'text': '<p>Another option is to use plain ol\' HTTP PUT:</p>\n\n<pre><code>WebClient webclient = new WebClient();\nwebclient.Credentials = new NetworkCredential(_userName, _password, _domain);\nwebclient.UploadFile(remoteFileURL, "PUT", FilePath);\nwebclient.Dispose();\n</code></pre>\n\n<p>Where remoteFileURL points to your SharePoint document library...</p>\n'}, {'answer_id': 47186, 'author': 'ErikE', 'author_id': 4855, 'author_profile': 'https://Stackoverflow.com/users/4855', 'pm_score': 3, 'selected': False, 'text': '<p>There are a couple of things to consider:</p>\n\n<ul>\n<li>Copy.CopyIntoItems <strike>needs the document to be already present at some server</strike>. The document is passed as a parameter of the webservice call, which will limit how large the document can be. (See <a href="http://social.msdn.microsoft.com/Forums/en-AU/sharepointdevelopment/thread/e4e00092-b312-4d4c-a0d2-1cfc2beb9a6c" rel="nofollow noreferrer">http://social.msdn.microsoft.com/Forums/en-AU/sharepointdevelopment/thread/e4e00092-b312-4d4c-a0d2-1cfc2beb9a6c</a>)</li>\n<li>the \'http put\' method (ie webdav...) will only put the document in the library, but not set field values</li>\n<li>to update field values you can call Lists.UpdateListItem after the \'http put\' </li>\n<li>document libraries can have directories, you can make them with \'http mkcol\'</li>\n<li>you may want to check in files with Lists.CheckInFile</li>\n<li>you can also create a custom webservice that uses the SPxxx .Net API, but that new webservice will have to be installed on the server. It could save trips to the server.</li>\n</ul>\n'}, {'answer_id': 3763626, 'author': 'Luke Hutton', 'author_id': 368552, 'author_profile': 'https://Stackoverflow.com/users/368552', 'pm_score': 3, 'selected': False, 'text': '<pre><code>public static void UploadFile(byte[] fileData) {\n  var copy = new Copy {\n    Url = "http://servername/sitename/_vti_bin/copy.asmx", \n    UseDefaultCredentials = true\n  };\n\n  string destinationUrl = "http://servername/sitename/doclibrary/filename";\n  string[] destinationUrls = {destinationUrl};\n\n  var info1 = new FieldInformation\n                {\n                  DisplayName = "Title", \n                  InternalName = "Title", \n                  Type = FieldType.Text, \n                  Value = "New Title"\n                };\n\n  FieldInformation[] info = {info1};\n  var copyResult = new CopyResult();\n  CopyResult[] copyResults = {copyResult};\n\n  copy.CopyIntoItems(\n    destinationUrl, destinationUrls, info, fileData, out copyResults);\n}\n</code></pre>\n\n<p><strong>NOTE:</strong> Changing the 1st parameter of <code>CopyIntoItems</code> to the file name, <code>Path.GetFileName(destinationUrl)</code>, makes the unlink message disappear.</p>\n'}]
['https://Stackoverflow.com/questions/31868', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3362/']