3

I am building a Console application in which I am programmatically trying to create a site collection in a tenant, using SharePoint object model. The code is as follows. But I am getting an error saying "User Does Not Exist or Is Not Unique."

using (SPSite tAdminSite = new SPSite("http://tenant-admin-url"))
{
string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
SPSite newSite = tAdminSite.SelfServiceCreateSite("http://siteUrl", "Test Site", "Site created programmatically", 1033, "STS#0", userName, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, tAdminSite.SiteSubscription);                   
}

Can anyone please help me? The user is a valid Windows (Domain) user.

1

I could solve this issue. Turns out that, SharePoint expects every parameter for the Owner and the Contact to have values and hence we can't pass those as null. So, the updated code, which works is as follows. Only the relevant line is shown. Hope it helps someone facing a similar issue.

SPSite newSite = tAdminSite.SelfServiceCreateSite("http://siteUrl", "Test Site", "Site created programmatically", 1033, "STS#0", userLoginName, userName, userEmail, userLoginName, userName, userEmail, string.Empty, tAdminSite.SiteSubscription);

Note: User Login Name and User Name look different in case of Claims Based Auth. For example, User Login Name is in the format i:0#.w|DomainName\UserName. User Name is in the format DomainName\UserName. Also, I have passed the same information for both Owner and Contact. We can use different values, if we have.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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