2013-04-04 62 views
0

我從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」複製類沒有在我的項目中找到。我該如何解決這個問題,或者有另一種方法來達到我的目標。

+1

我認爲在SP 2013中asmx web服務[不建議使用](http://msdn.microsoft.com/en-us/library/jj164060.aspx#DeprecatedAPIs) – Flowerking 2013-04-04 12:42:49

+0

這裏不太清楚你想在這裏做什麼...所以用戶將轉到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

+0

嗨,我陷入了類似的問題,你過來怎麼樣? – Akshay 2017-10-19 06:40:51

回答

1

參閱這篇 http://www.ktskumar.com/blog/2009/03/upload-document-from-local-machine-to-sharepoint-library/

您必須添加的Web引用Web服務的URL,而不是服務引用。 在Visual Studio項目上,右鍵單擊引用,然後選擇添加服務引用。 在添加服務引用彈出窗口中,單擊框底部的高級按鈕, 現在服務引用設置彈出窗口將打開,我們必須單擊「添加Web引用」按鈕。然後提供Web服務URL並單擊「添加引用」按鈕以將Web服務URL包含到項目中。

相關問題