通过SharePoint 2010 Web服务上传文档

一个如何通过SharePoint 2010 webservices上载或添加一个文档到文档库的例子。

首先创建一个服务引用

CopyServiceRef.Copy copyService = new CopyServiceRef.Copy();
copyService.Url = _spWeb.url+”/_vti_bin/copy.asmx”;
copyService.Credentials = System.Net.CredentialCache.DefaultCredentials;
设置源和目标库

string sourceUrl = “C:\\mydoc.doc”; ->> or a file from file Upload control
string[] destinationUrl = “http://SharePointServer/Shared Documents/mydoc.doc””;
copyService.CopyResult cResult1 = new copyService.CopyResult();
copyService.CopyResult cResult2 = new copyService.CopyResult();
copyService.CopyResult[] cResultArray = { cResult1, cResult2 };

//Reading the document contents in to stream
FileStream str = new FileStream(sourceUrl, FileMode.Open, FileAccess.Read);
byte[] fileContents = new Byte[str.Length];
str.Read(fileContents, 0, Convert.ToInt32(str.Length));
str.Close();

//Copy the document from SourceUrl to destinationUrl
int copyresult = copyService.CopyIntoItems(sourceUrl, destinationUrl, fileContents, out ArrayOfResults);
拷贝结果将包含0以指示该操作已完成。

 

参考资料

Upload a document using web service in SharePoint 2010

posted @ 2010-09-06 22:38  Sunmoonfire  阅读(121)  评论(0)    收藏  举报