通过WSS 3.0版本公开的内置Web服务将文件上载到SharePoint服务器上的文档库的最佳方法是什么?
按照两个初步答案......
我们肯定需要使用Web服务层,因为我们将从远程客户端应用程序进行这些调用.
WebDAV方法对我们有用,但我们更愿意与Web服务集成方法保持一致.
还有一个上传文件的网络服务,痛苦但一直有效.
你指的是"复制"服务吗?我们已成功使用此服务的CopyIntoItems方法.这是仅使用WSS Web服务API将文件上载到文档库的推荐方法吗?
我已将我们的代码发布为建议的答案.
And*_*age 17
使用WSS"复制"Web服务将文档上载到库的示例...
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)
{
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
另一种选择是使用普通的'HTTP PUT:
WebClient webclient = new WebClient();
webclient.Credentials = new NetworkCredential(_userName, _password, _domain);
webclient.UploadFile(remoteFileURL, "PUT", FilePath);
webclient.Dispose();
Run Code Online (Sandbox Code Playgroud)
remoteFileURL指向SharePoint文档库的位置...
有几件事需要考虑:
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);
}
Run Code Online (Sandbox Code Playgroud)
注意:将第一个参数更改为CopyIntoItems文件名Path.GetFileName(destinationUrl),会使取消链接消息消失.
| 归档时间: |
|
| 查看次数: |
64282 次 |
| 最近记录: |