2009-06-12 51 views
4

我正在嘗試使用SharePoint Copy Web服務的CopyIntoItems方法將文檔文件加載到SharePoint中的文檔庫中。如何使用SharePoint Copy Web服務的CopyIntoItems方法?

下面的代碼執行並返回0(成功)。此外,CopyResult []數組返回1值,並帶有「成功」結果。但是,我無法在庫中的任何位置找到該文檔。

我有兩個問題:

  1. 任何人都可以看到什麼錯我的代碼或暗示的變化?
  2. 任何人都可以建議我怎麼可以在服務器端進行調試。我沒有大量的SharePoint經驗。如果我可以通過日誌記錄或服務器端的其他方法跟蹤發生了什麼,它可能會幫助我弄清楚發生了什麼。

代碼示例:

string[] destinationUrls = { Uri.EscapeDataString("https://someaddress.com/Reports/Temp") }; 

SPCopyWebService.FieldInformation i1 = new SPCopyWebService.FieldInformation { DisplayName = "Name", InternalName = "Name", Type = SPListTransferSpike1.SPCopyWebService.FieldType.Text, Value = "Test1Name" }; 
SPCopyWebService.FieldInformation i2 = new SPCopyWebService.FieldInformation { DisplayName = "Title", InternalName = "Title", Type = SPListTransferSpike1.SPCopyWebService.FieldType.Text, Value = "Test1Title" }; 

SPCopyWebService.FieldInformation[] info = { i1, i2 }; 

SPCopyWebService.CopyResult[] result; 

byte[] data = File.ReadAllBytes("C:\\SomePath\\Test1Data.txt"); 

uint ret = SPCopyNew.CopyIntoItems("", destinationUrls, info, data, out result); 

編輯得到的東西的工作:

我得到了我的代碼加入 「http://null」 到SourceUrl領域工作。 Nat的答案可能會出於這個原因。這是我爲改變它而改變的一行。

// Change 
uint ret = SPCopyNew.CopyIntoItems("http://null", destinationUrls, info, data, out result); 
+1

應該不是使用Uri.EscapeUriString而不是Uri.EscapeDataString? – 2010-02-28 13:08:31

+0

Uri.EscapeUriString對我更好。 – 2013-12-19 17:25:39

回答

6

我認爲這個問題可能是在嘗試使用web服務設置「名稱」屬性。我做了一些失敗。 鑑於「名稱」爲文檔的名稱,你可能有一些成功的

string targetDocName = "Test1Name.txt"; 
    string destinationUrl = Uri.EscapeDataString("https://someaddress.com/Reports/Temp/" + targetDocName); 
    string[] destinationUrls = { destinationUrl }; 

    SPCopyWebService.FieldInformation i1 = new SPCopyWebService.FieldInformation { DisplayName = "Title", InternalName = "Title", Type = SPListTransferSpike1.SPCopyWebService.FieldType.Text, Value = "Test1Title" }; 
    SPCopyWebService.FieldInformation[] info = { i1}; 
    SPCopyWebService.CopyResult[] result; 
    byte[] data = File.ReadAllBytes("C:\\SomePath\\Test1Data.txt"); 
    uint ret = SPCopyNew.CopyIntoItems(destinationUrl, destinationUrls, info, data, out result); 

注:我已經使用了「目標」的「源」屬性。 Don't quite know why, but it does the trick

1

我不很瞭解你綁做什麼,但如果你想從本地目錄中的文件上傳至SharePoint庫,我建議你創建一個Web客戶端和使用uploadata:

示例(VB.NET):

dim webclient as Webclient 
webClient.UploadData("http://srvasddress/library/filenameexample.doc", "PUT", filebytes) 

然後你只需使用列表Web服務,喜歡的東西在文件中檢查:

listService.CheckInFile("http://srvasddress/library/filenameexample.doc", "description", "1") 

希望它有一些幫助。

編輯:不要忘記設置Web客戶端憑證等

編輯2:使用此更新metada領域:

listService.UpdateListItems("Name of the Library, batchquery) 

你可以找到關於構建批量查詢在這裏信息:link

+0

+1 - 這是一個好方法。但是,我想同時設置與該文件關聯的元數據。 – 2009-06-15 14:59:50

1

sourceurl在Sharepoint中使用。這是一個鏈接回到「源文件」。在文檔庫中,將鼠標懸停在項目上方,右側出現一個向下的三角形。點擊它,調出一個菜單。點擊「查看屬性」選項。在此頁面上,您將看到以下「此項目是http://null(轉至源項目|取消鏈接)的副本」

因爲我們使用複製功能Sharepoint正在跟蹤「源項目」作爲文檔管理功能。

相關問題