SharePoint网站未生成

时间:2018-07-06 07:11:52

标签: sharepoint office365 microsoft-graph

我有一个简单的Web服务,它使用GraphApi按需创建组。然后继续在相关的SharePoint网站上初始化一个简单的文件夹结构。

出于某种原因,没有问题地对它进行分组,正确地分配了用户,但是当使用Sharepoint API添加一些文件夹时,我从站点中收到一个奇妙的 404错误。似乎该网站不是自动创建的。

下面的一些代码片段:

string result = "";
try
{
    if (project== null)
        throw new ArgumentNullException("Project");

    GraphServiceClient client = GraphServices.GroupsService.GetAuthenticatedClient();

    //Get project owners
    List<string> owners = new List<string>();
    Director projectDirector = project.GetDirector();
    if (projectDirector != null)
        owners.Add(projectDirector.Code);
    List<Microsoft.Graph.User> ownerUsers = await UsersService.GetUsers(client, owners.Distinct().ToList());

    //Get project Members
    List<string> members = project.GetAllMembers();
    List<Microsoft.Graph.User> memberUsers = await UsersService.GetUsers(client, members);

    //Create group
    string groupMail = proyecto.ProyectoID.ToLower();

    string groupDisplayName = project.ProjectID.ToUpper() + " - " + project.Name;
    string groupDescription = project.Description.ToString();
    Microsoft.Graph.Group projectGroup = await GroupsService.CreateUnifiedGroup(client, groupMail, groupDisplayName, groupDescription, true, ownerUsers, memberUsers);

    if (projectGroup != null)
    {
        result = projectGroup.Id;
    }

    Microsoft.Graph.Drive groupDrive = projectGroup.Drive;

    Thread.Sleep(30000);
    using (var clientContext = new ClientContext("https://nae1.sharepoint.com/sites/" + groupMail))
    {
        //Login
        SecureString securePass = new SecureString();
        string user = WebConfigurationManager.AppSettings["SharepointUser"];
        string pass = WebConfigurationManager.AppSettings["SharepointPass"];
        foreach (char c in pass) { securePass.AppendChar(c); }
        clientContext.Credentials = new SharePointOnlineCredentials(user, securePass);

        //Creacion de carpetes
        Web sharepointSite = clientContext.Web;
        Microsoft.SharePoint.Client.List list = sharepointSite.Lists.GetByTitle("Documentos");

        list.EnableFolderCreation = true;
        list.RootFolder.Folders.OrderBy(x => x.Name);
        list.Update();

        List<string> newFolders = new List<string>(new string[] { "01. Folder A", "02. Folder B", "03. Folder C" });
        foreach (string folderName in newFolders)
        {
            ListItemCreationInformation folder = new ListItemCreationInformation()
            {
                UnderlyingObjectType = FileSystemObjectType.Folder,
                LeafName = folderName
            };
            Microsoft.SharePoint.Client.ListItem folderItem = list.AddItem(folder);
            folderItem["Title"] = folderName;
            folderItem.Update();
        }
        clientContext.ExecuteQuery();

        clientContext.Load(sharepointSite, loadSiteGroups => loadSiteGroups.SiteGroups);
        clientContext.Load(sharepointSite, loadSiteUsers => loadSiteUsers.SiteUsers);
        clientContext.ExecuteQueryRetry();
        UserCollection users = sharepointSite.SiteUsers;
        GroupCollection groups = sharepointSite.SiteGroups;
        groups.Where(z => z.Id == 4).FirstOrDefault().Users.AddUser(users.Where(x => x.Id == 9).FirstOrDefault());
        clientContext.ExecuteQuery();

    }

    return result;
}
catch (Exception ex)
{
    Logger.Current.Error("[ProyectoService] - CrearOfficeGroupByProyecto - Error " + ex.Message, ex);
    return result;
}

谷歌搜索解决方案,但没有任何效果,在这里也找不到解决方案。

那我想念什么?

0 个答案:

没有答案