0

when I create team site using the code from the following URL: Create Modern Sites in SharePoint Online using CSOM

it show the error in the given image.

enter image description here

1
  • can you paste the code ? Looks like its a bit different from what is there in the answer Mar 27, 2018 at 11:06

1 Answer 1

0

I see that you are using this code in a console application.

It looks like your code is executing before the team site is created which causes the 404 error.

You need to wait for the site to be created using the Wait or GetAwaiter method as below in a console application:

TeamSiteCollectionCreationInformation modernteamSiteInfo = new TeamSiteCollectionCreationInformation
{
    Description = "Test modern teamsite description",
    DisplayName = "Test Modern Team Site",
    Alias = "TestModernTeamSite",
    IsPublic = true,
    //Classification="IT"                       
};

var createModernSite = context.CreateSiteAsync(modernteamSiteInfo).GetAwaiter().GetResult();
// further code once the site is created

or

context.CreateSiteAsync(modernteamSiteInfo).Wait();

Use this in the console and write your code after the Wait.

3
  • thanks alot var createModernSite = context.CreateSiteAsync(modernteamSiteInfo).GetAwaiter().GetResult(); // this is working fine again thanks Sir :) Mar 27, 2018 at 12:27
  • Can we set the owner of team site ? Mar 27, 2018 at 13:15
  • Yes, we can. Can you ask it as another question? I will attempt to answer there. I can't answer it in the comments as its a bit long and also out of scope for the current question :) Mar 28, 2018 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.