通过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);
参考资料
浙公网安备 33010602011771号