1

我需要使用客户端对象模型在 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();
4

1 回答 1

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();
        }
于 2012-07-13T11:09:05.770 回答