1
這可能看起來像一個愚蠢的問題,但我似乎無法在Google上找到任何答案。使用SharePoint客戶端對象模型重命名文件?
我寫了一個查詢SharePoint的方法,並根據我指定的文檔名稱參數重命名文檔。我已經使用類似的方法來重命名文件夾,這一直很好但是當我試圖重命名文件,我得到一個ArgumentOutOfRangeException
這裏是我的代碼:
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;
}
}
}
任何幫助,將不勝感激。謝謝!