我需要在客户端对象模型的sharepoint中创建子文件夹,父文件夹是现有的,这是我的代码,但是我收到了这个错误,
文件名无效。 您指定的文件名无法使用。它可能是现有文件或目录的名称,或者您可能无权访问该文件。
ContentTypeCollection listContentTypes = list.ContentTypes;
clientContext.Load(listContentTypes, types => types.Include
(type => type.Id, type => type.Name,
type => type.Parent));
var result = clientContext.LoadQuery(listContentTypes.Where
(c => c.Name == "Folder"));
clientContext.ExecuteQuery();
ContentType folderContentType = result.FirstOrDefault();
ListItemCreationInformation newItem = new ListItemCreationInformation();
newItem.UnderlyingObjectType = FileSystemObjectType.Folder;
newItem.FolderUrl = @"http://mysite/sites/org" + "/" + listName;
if (!folderName1.Equals(string.Empty))
{
newItem.FolderUrl += "/" + folderName1;
}
newItem.LeafName = folderName2;
ListItem item = list.AddItem(newItem);
item["ContentTypeId"] = folderContentType.Id.ToString();
item["Title"] = folderName2;
item.Update();
clientContext.Load(list);
clientContext.ExecuteQuery();
答案 0 :(得分:0)
如果您需要创建文件夹,可以尝试使用以下代码:
using (var clientContext = new ClientContext(@"http://server"))
{
var web = clientContext.Web;
var lst = web.Lists.GetByTitle("CheckDocLib");
var fld1 = lst.RootFolder.Folders.Add("FirstLevel1");
var fld2 = fld1.Folders.Add("SecondLevel1");
fld1.Update();
fld2.Update();
clientContext.ExecuteQuery();
}