Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
Sharepoint 2010 是否使用SharePoint客户端对象模型重命名文件?_Sharepoint 2010_Sharepointdocumentlibrary_Sharepoint Clientobject - Fatal编程技术网

Sharepoint 2010 是否使用SharePoint客户端对象模型重命名文件?

Sharepoint 2010 是否使用SharePoint客户端对象模型重命名文件?,sharepoint-2010,sharepointdocumentlibrary,sharepoint-clientobject,Sharepoint 2010,Sharepointdocumentlibrary,Sharepoint Clientobject,这似乎是一个愚蠢的问题,但我似乎在谷歌上找不到任何答案 我已经编写了一个查询SharePoint并根据指定的document name参数重命名文档的方法。我使用了类似的方法来重命名文件夹,效果很好,但是当我尝试重命名文件时,会出现ArgumentOutOfRange异常 这是我的密码: public bool RenameFileInDocumentLibrary(string documentName, string newDocumentName, ClientContext client

这似乎是一个愚蠢的问题,但我似乎在谷歌上找不到任何答案

我已经编写了一个查询SharePoint并根据指定的document name参数重命名文档的方法。我使用了类似的方法来重命名文件夹,效果很好,但是当我尝试重命名文件时,会出现ArgumentOutOfRange异常

这是我的密码:

public bool RenameFileInDocumentLibrary(string documentName, string newDocumentName, ClientContext clientContext)
        {
            {
                bool isDocumentRenamed = false;

                string url = "MySharePointSite";

                List list = clientContext.Web.Lists.GetByTitle("MyDocLib");

                CamlQuery query = new CamlQuery();
                query.ViewXml = "<View Scope=\"RecursiveAll\"> " +
                            "<Query>" +
                                "<Where>" +
                                    "<And>" +
                                        "<Eq>" +
                                            "<FieldRef Name=\"FSObjType\" />" +
                                            "<Value Type=\"Integer\">2</Value>" +
                                         "</Eq>" +
                                          "<Eq>" +
                                            "<FieldRef Name=\"Title\"/>" +
                                            "<Value Type=\"Text\">" + documentName + "</Value>" +
                                          "</Eq>" +
                                    "</And>" +
                                 "</Where>" +
                            "</Query>" +
                            "</View>";

                var files = list.GetItems(query);

                clientContext.Load(list);
                clientContext.Load(list.Fields);
                clientContext.Load(files, fs => fs.Include(fi => fi["Title"],
                    fi => fi["DisplayName"],
                    fi => fi["FileLeafRef"]));
                clientContext.ExecuteQuery();

                if (files.Count == 0)
                {
                    files[0]["Title"] = newDocumentName;
                    files[0]["FileLeafRef"] = newDocumentName;
                    files[0].Update();
                    clientContext.ExecuteQuery();
                    isDocumentRenamed = true;
                }

                return isDocumentRenamed;
            }
        }
    }  
public bool重命名FileInDocumentLibrary(string documentName、string newDocumentName、ClientContext ClientContext)
{
{
bool isdocumentrename=false;
字符串url=“MySharePointSite”;
List List=clientContext.Web.Lists.GetByTitle(“MyDocLib”);
CamlQuery query=新建CamlQuery();
query.ViewXml=“”+
"" +
"" +
"" +
"" +
"" +
"2" +
"" +
"" +
"" +
“”+documentName+“”+
"" +
"" +
"" +
"" +
"";
var files=list.GetItems(查询);
clientContext.Load(列表);
clientContext.Load(list.Fields);
Load(文件,fs=>fs.Include(fi=>fi[“Title”],
fi=>fi[“显示名称”],
fi=>fi[“FileLeafRef”]);
clientContext.ExecuteQuery();
如果(files.Count==0)
{
文件[0][“Title”]=newDocumentName;
文件[0][“FileLeafRef”]=newDocumentName;
文件[0]。更新();
clientContext.ExecuteQuery();
IsDocumentRename=true;
}
返回已重命名的文档;
}
}
}  

在此方面的任何帮助都将不胜感激。谢谢

您需要使用ListItems文件成员:

string newPath = files[0]["FileDirRef"] + "/" + "MyNewFileName" + ".extension";
files[0].File.MoveTo(newPath, MoveOperations.Overwrite);
files[0].Update();
clientContext.ExecuteQuery();