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

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

1 Answer 1


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,

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



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

  • thanks alot var createModernSite = context.CreateSiteAsync(modernteamSiteInfo).GetAwaiter().GetResult(); // this is working fine again thanks Sir :) Commented Mar 27, 2018 at 12:27
  • Can we set the owner of team site ? Commented 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 :) Commented 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.