我从http://ktskumar.wordpress.com/2009/03/03/upload-document-from-local-machine-to-sharepoint-library/以下代码使用Web服务将文档上传到SharePoint文件夹。我已添加https://mysite.sharepoint.com/_vti_bin/Copy.asmx(此网站在Sharepoint Online上)作为我的服务参考。使用WebService将文档从本地计算机上传到SharePoint 2013库
//Copy WebService Settings
string webUrl = "https://mySite.sharepoint.com";
WSCopy.Copy copyService = new WSCopy.Copy();
copyService.Url = webUrl + "/_vti_bin/copy.asmx";
copyService.Credentials = System.Net.CredentialCache.DefaultCredentials;
//Source and Destination Document URLs
string sourceUrl = "http://localhost/Shared Documents/Sample.doc";
string destinationUrl = "E:\\DocumentsSample.doc";
//Variables for Reading metadata’s of a document
WSCopy.FieldInformation fieldInfo = new WSCopy.FieldInformation();
WSCopy.FieldInformation[] fieldInfoArray = { fieldInfo };
WSCopy.CopyResult cResult1 = new WSCopy.CopyResult();
WSCopy.CopyResult cResult2 = new WSCopy.CopyResult();
WSCopy.CopyResult[] cResultArray = { cResult1, cResult2 };
//Receive a Document Contents into Byte array (filecontents)
byte[] fileContents = new Byte[4096];
uint copyresult = copyService.GetItem(sourceUrl, out fieldInfoArray, out fileContents);
if (copyresult == 0)
{
Console.WriteLine("Document downloaded Successfully, and now it's getting saved in location " + destinationUrl);
//Create a new file and write contents to that document
FileStream fStream = new FileStream(destinationUrl, FileMode.Create, FileAccess.ReadWrite);
fStream.Write(fileContents, 0, fileContents.Length);
fStream.Close();
}
else
{
Console.WriteLine("Document Downloading gets failed...");
}
Console.Write("Press any key to exit...");
Console.Read();
这里WSCopy是服务引用和“WSCopy.Copy”复制类没有在我的项目中找到。我该如何解决这个问题,或者有另一种方法来达到我的目标。
我认为在SP 2013中asmx web服务[不建议使用](http://msdn.microsoft.com/en-us/library/jj164060.aspx#DeprecatedAPIs) – Flowerking 2013-04-04 12:42:49
这里不太清楚你想在这里做什么...所以用户将转到Sharepoint,然后单击某处浏览其本地文件夹以选择文件,然后将文件上载到Sharepoint?如果这是你试图实现的原因,那么你可能想看看这个:[SharepointPlus createFile](http://aymkdn.github.io/SharepointPlus/symbols/%24SP%28%29.html#.createFile) ;你必须使用旧版浏览器的[http://www.html5rocks.com/en/tutorials/file/dndfiles/](HTML5 File API)或Flash解决方案......如果这不是你想要的做,然后请再解释一下:-) – AymKdn 2013-04-06 11:47:34
嗨,我陷入了类似的问题,你过来怎么样? – Akshay 2017-10-19 06:40:51