Search This Blog

Thursday, March 19, 2015

Sharepoint\System "User not found"


Look at the code below and if you try to run this code then it will give error while creating a site because sharepoint doesn't find super admin account



 SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(url))
                {
                    SPSiteCollection workspaces = site.WebApplication.Sites;
                    using (SPSite workspaceSite = workspaces.Add("URL", "Name", "Description", 1033, "BDR#0", SPContext.Current.Web.CurrentUser.LoginName, SPContext.Current.Web.CurrentUser.Name, SPContext.Current.Web.CurrentUser.Email))
                    {
                        return workspaceSite.ID;
                    }
                }
            });




So the workaround of this problem is to get the default site administrator of current site collection and put it in new site collection


 SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(url))
                {
                    SPUser administrator = site.RootWeb.SiteAdministrators[0];
                    SPSiteCollection workspaces = site.WebApplication.Sites;
                    using (SPSite workspaceSite = workspaces.Add("URL", "Name", "Description", 1033, "BDR#0", administrator.LoginName, administrator.Name, administrator.Email))
                    {
                       return workspaceSite.ID;
                    }
                }
            });


BDR#0 is the template Name for document center site. You can use any of the following in site creation process:

IDNameDisplay group
0GLOBAL#0Global template
1STS#0Team Site
1STS#1Blank Site
1STS#2Document Workspace
2MPS#0Basic Meeting Workspace
2MPS#1Blank Meeting Workspace
2MPS#2Decision Meeting Workspace
2MPS#3Social Meeting Workspace
2MPS#4Multipage Meeting Workspace
3CENTRALADMIN#0Central Admin Site
4WIKI#0Wiki Site
7BDR#0Document Center
9BLOG#0Blog
15SGS#0Group Work Site
16TENANTADMIN#0Tenant Admin Site
20SPS#0SharePoint Portal Server Site
21SPSPERS#0SharePoint Portal Server Personal Space
22SPSMSITE#0Personalization Site
30SPSTOC#0Contents area Template
31SPSTOPIC#0Topic area template
32SPSNEWS#0News Site
33SPSNHOME#0News Site
34SPSSITES#0Site Directory
36SPSCOMMU#0Community area template
38SPSREPORTCENTER#0Report Center
39CMSPUBLISHING#0Publishing Site
40OSRV#0Shared Services Administration Site
47SPSPORTAL#0Collaboration Portal
50SRCHCEN#0Enterprise Search Center
51PROFILES#0Profiles
52BLANKINTERNETCONTAINER#0Publishing Portal
53BLANKINTERNET#0Publishing Site
53BLANKINTERNET#1Press Releases Site
53BLANKINTERNET#2Publishing Site with Workflow
54SPSMSITEHOST#0My Site Host
56ENTERWIKI#0Enterprise Wiki
61visprus#0Visio Process Repository
90SRCHCENTERLITE#0Basic Search Center
90SRCHCENTERLITE#1Basic Search Center
2000SRCHCENTERFAST#0FAST Search Center
2764ACCSRV#0Access Services Site
2764ACCSRV#1Assets Web Database
2764ACCSRV#3Charitable Contributions Web Database
2764ACCSRV#4Contacts Web Database
2764ACCSRV#6Issues Web Database
2764ACCSRV#5Projects Web Database
3100PPSMASite#0PerformancePoint
3200BICenterSite#0Business Intelligence Center
14483OFFILE#0(obsolete) Records Center
14483OFFILE#1Records Center

No comments:

Post a Comment