2011-06-01 55 views
3

我正在上傳文件到sharepoint ..但是我想提供一個自定義名稱,而不是它繼承了即時上傳文件的名稱。更新listitem屬性不提交更改爲共享點

我的代碼是基於這樣的解決方案:http://www.codeproject.com/Articles/103503/How-to-upload-download-a-document-in-SharePoint-20.aspx

但是這並不工作。

另外,我也想提供該文件的標題: ,所以我想更新標題:

uploadFile.ListItemAllFields.FieldValues["Title"] = "my custom title"; 

然而,一旦該文件已完成其upload..i登錄SharePoint和注意標題沒有被應用。

我該如何整合上傳文件和應用新名稱?

千恩萬謝,

編輯:

 using (var clientContext = GetNewContext()) 
     { 
      var uploadLocation = string.Format("{0}{1}/{2}", SiteUrl, Helpers.ListNames.RequestedDocuments, Path.GetFileName(document)); 

      //Get Document List 
      var documentslist = clientContext.Web.Lists.GetByTitle(Helpers.ListNames.RequestedDocuments); 

      var fileCreationInformation = new FileCreationInformation 
      { 
       Content = System.IO.File.ReadAllBytes(document), //Assign to content byte[] i.e. documentStream 
       Overwrite = true, //Allow owerwrite of document 
       Url = uploadLocation //Upload URL, 

      }; 

      var uploadFile = documentslist.RootFolder.Files.Add(fileCreationInformation); 

      uploadFile.ListItemAllFields.FieldValues["Title"] = title; 

      uploadFile.ListItemAllFields.Update(); 

      clientContext.ExecuteQuery();   
     } 
     site.SubmitChanges(ConflictMode.FailOnFirstConflict, true); 

回答

2

你叫設置字段值後更新?

uploadFile.ListItemAllFields.Update(); 
+0

是,看到更新的問題 – nologo 2011-06-01 13:27:01

0

,而不是設置:

uploadFile.ListItemAllFields.FieldValues["Title"] = title; 
uploadFile.ListItemAllFields.Update(); 

進行如下設置:

uploadFile.ListItemAllFields["Title"] = title; 
uploadFile.ListItemAllFields.Update();