【Sharepoint对象模型】MOSS根据模板添加子网站

 1        SPSecurity.RunWithElevatedPrivileges(delegate ()

 2                         {

 3                             SPWebCollection sPWebCollection = web.Webs;

 4                             SPWebTemplate tp = null ;

 5                             SPWebTemplateCollection tpc2 = web.GetAvailableWebTemplates((uint)2052);

 6                             foreach (SPWebTemplate wt in tpc2)

 7                             {

 8                                 if (wt.Title == "NewSite" )

 9                                 {

10                                     tp = wt;

11                                     break;

12                                 }

13                             }

14                             if (tp != null )

15                             {

16  

17                                 try

18                                 {

19                                     SPWeb sPWeb = sPWebCollection.Add("pm_" +spi.ID.ToString(), ProjectName.Text, "", (uint )2052, tp, true, false);

20                                     sPWeb.AllowUnsafeUpdates = true;

21                                     sPWeb.Update();

22                                     sPWeb.BreakRoleInheritance( true);

23                                     Label2.Text = "创建子网站成功!" ;

24                                 }

25                                 catch (Exception ex)

26                                 {

27                                     Label2.Text=ex.ToString();

28                                 }

29                             }

30                         });

 

你可能感兴趣的:(SharePoint)