更新的列表项属性不会改变commiting到SharePoint [英] updated listitem attributes aren't commiting changes to sharepoint

查看:183
本文介绍了更新的列表项属性不会改变commiting到SharePoint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时上传文件到SharePoint。不过我想提供一个自定义的名称,而不是它继承了文件,IM上传的名称。



我的代码是基于该解决方案:的 http://www.codeproject.com/Articles/103503/How-to-upload-download-a-document-in-SharePoint-20.aspx



然而,这并不工作。



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

  uploadFile.ListItemAllFields.FieldValues [标题] =我的自定义标题; 



然而,一旦该文件已完成了upload..i登录到SharePoint并注意标题已处理不当应用。



我怎么能G642.44各级上传文件并应用新的名字吗?



千恩万谢,



编辑:

 (VAR clientContext = GetNewContext())
{
VAR uploadLocation =的String.Format({0} {1} / {2},主页,Helpers.ListNames.RequestedDocuments,Path.GetFileName(文件));

//获取文档列表
VAR documentslist = clientContext.Web.Lists.GetByTitle(Helpers.ListNames.RequestedDocuments);

变种fileCreationInformation =新FileCreationInformation
{
含量= System.IO.File.ReadAllBytes(文件),//分配给内容的byte []即documentStream
覆盖= TRUE,//允许owerwrite文件
URL = uploadLocation // URL上传,

}的;

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

uploadFile.ListItemAllFields.FieldValues [标题] =称号;

uploadFile.ListItemAllFields.Update();

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


解决方案

您缺少一个电话后,你clientContext.Load将文件添加到文件的集合。看到这些博客文章以了解更多信息:



http://www.learningsharepoint.com/2010/07/12/programmatically-upload-document-using-client-object-model-sharepoint -2010 /



http://www.zimmergren.net/archive/2010/06/10/sp-2010-uploading-files - 使用的非客户端OM-在SharePoint的2010.aspx


i'm uploading a document to sharepoint.. however i would like to provide a custom name rather than it inherit the name of the file which im uploading.

my code was based on this solution: http://www.codeproject.com/Articles/103503/How-to-upload-download-a-document-in-SharePoint-20.aspx

however this doesnt work.

Additionally, i would also like to provide a title of the file: so i wanted to update the title:

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

However, once the file has completed its upload..i login to sharepoint and notice the title hasnt been applied.

how can i intergrate uploading the file and applying a new name?

many thanks,

EDIT:

        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);

解决方案

You are missing a call to clientContext.Load after you add the file to the Files collection. See these blog posts for more information:

http://www.learningsharepoint.com/2010/07/12/programmatically-upload-document-using-client-object-model-sharepoint-2010/

http://www.zimmergren.net/archive/2010/06/10/sp-2010-uploading-files-using-the-client-om-in-sharepoint-2010.aspx

这篇关于更新的列表项属性不会改变commiting到SharePoint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆