Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更新的listitem属性不是';提交对sharepoint的更改_C#_Sharepoint 2010 - Fatal编程技术网

C# 更新的listitem属性不是';提交对sharepoint的更改

C# 更新的listitem属性不是';提交对sharepoint的更改,c#,sharepoint-2010,C#,Sharepoint 2010,我正在将文档上载到sharepoint。。然而,我想提供一个自定义名称,而不是它继承的文件名,我上传 我的代码基于此解决方案: 然而,这不起作用 此外,我还想提供该文件的标题: 所以我想更新标题: uploadFile.ListItemAllFields.FieldValues["Title"] = "my custom title"; 但是,一旦文件完成上传,我就登录到sharepoint并注意到标题尚未应用 如何整合上传文件和应用新名称 非常感谢, 编辑: 设置字段值后是否调用Update

我正在将文档上载到sharepoint。。然而,我想提供一个自定义名称,而不是它继承的文件名,我上传

我的代码基于此解决方案:

然而,这不起作用

此外,我还想提供该文件的标题: 所以我想更新标题:

uploadFile.ListItemAllFields.FieldValues["Title"] = "my custom title";
但是,一旦文件完成上传,我就登录到sharepoint并注意到标题尚未应用

如何整合上传文件和应用新名称

非常感谢,

编辑:


设置字段值后是否调用Update

uploadFile.ListItemAllFields.Update();

将文件添加到文件集合后,缺少对clientContext.Load的调用。有关更多信息,请参阅以下博客帖子:

此代码示例来自上面链接的第一篇博文:

public Boolean UploadDocument(String fileName, String filePath, List metaDataList)   
{  
    SP.ClientContext ctx = new SP.ClientContext("http: //yoursharepointURL");  
    Web web = ctx.Web;  
    FileCreationInformation newFile = new FileCreationInformation();  
    newFile.Content = System.IO.File.ReadAllBytes(@"C: \TestFile.doc");  
    newFile.Url = " / " + fileName;  
    List docs = web.Lists.GetByTitle("Shared Documents");  
    Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);  
    context.Load(uploadFile);  
    context.ExecuteQuery();  
    SPClient.ListItem item = uploadFile.ListItemAllFields;  
    //Set the metadata  
    string docTitle = string.Empty;  
    item["Title"] = docTitle;  
    item.Update();  
    context.ExecuteQuery();  
}
而不是设置:

uploadFile.ListItemAllFields.FieldValues["Title"] = title;
uploadFile.ListItemAllFields.Update();
设置如下:

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

回答问题时,请在答案中添加代码示例。我和@nologo有同样的问题,但是你引用的两个站点都关闭了。
uploadFile.ListItemAllFields["Title"] = title;
uploadFile.ListItemAllFields.Update();