遵循两个初步答案...
此外,还有一个Web服务可以上传文件,但很麻烦,但始终可以正常工作。
Blockquote>
您是指"复制"服务吗?
我们已成功使用此服务的CopyIntoItems方法。 这是仅使用WSS Web服务API将文件上传到文档库的推荐方法吗?
我已经发布了我们的代码作为建议答案。
使用WSS"复制" Web服务将文档上载到库的示例...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| 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)
{
// ...
}
} |
另一种选择是使用普通的HTTP PUT:
1 2 3 4
| WebClient webclient = new WebClient();
webclient.Credentials = new NetworkCredential(_userName, _password, _domain);
webclient.UploadFile(remoteFileURL,"PUT", FilePath);
webclient.Dispose(); |
remoteFileURL指向您的SharePoint文档库的位置...
有几件事情要考虑:
-
Copy.CopyIntoItems
需要该文档在某些服务器上已经存在 strike>。文档作为webservice调用的参数传递,这将限制文档的大小。 (请参阅http://social.msdn.microsoft.com/Forums/en-AU/sharepointdevelopment/thread/e4e00092-b312-4d4c-a0d2-1cfc2beb9a6c)
-
'http put'方法(即webdav ...)只会将文档放入库中,而不会设置字段值
-
要更新字段值,可以在" http put"之后调用Lists.UpdateListItem
-
文档库可以具有目录,您可以使用" http mkcol"进行创建
-
您可能想使用Lists.CheckInFile检入文件
-
您还可以创建使用SPxxx .Net API的自定义Web服务,但是新的Web服务将必须安装在服务器上。它可以节省前往服务器的行程。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| public static void UploadFile(byte[] fileData) {
var copy = new Copy {
Url ="http://servername/sitename/_vti_bin/copy.asmx",
UseDefaultCredentials = true
};
string destinationUrl ="http://servername/sitename/doclibrary/filename";
string[] destinationUrls = {destinationUrl};
var info1 = new FieldInformation
{
DisplayName ="Title",
InternalName ="Title",
Type = FieldType.Text,
Value ="New Title"
};
FieldInformation[] info = {info1};
var copyResult = new CopyResult();
CopyResult[] copyResults = {copyResult};
copy.CopyIntoItems(
destinationUrl, destinationUrls, info, fileData, out copyResults);
} |
注意:将CopyIntoItems的第一个参数更改为文件名Path.GetFileName(destinationUrl),使取消链接消息消失。
我使用下面介绍的DocLibHelper包装器类祝您好运:http://geek.hubkey.com/2007/10/upload-file-to-sharepoint-document.html
不确定确切使用哪个Web服务,但是如果您可以使用SharePoint .NET API Dll,那么使用SPList和SPLibrary.Items.Add确实很容易。
从工作中的大学学院:
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.
There is additionally a web service to upload files, painful but works all the time.
I believe you are able to upload files via the FrontPage API but I don’t know of anyone who actually uses it.