Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. private void CreateNewSite(SPWeb web, string sSiteName,string sSiteTemplate)
  2. {
  3. string sSiteUrl = web.Url + "/" + sSiteName;
  4.  
  5. if (!SiteExists(sSiteUrl))
  6. {
  7. try
  8. {
  9. web.AllowUnsafeUpdates = true;
  10.  
  11.  
  12.  
  13. string url = sSiteName;
  14. string title = sSiteName;
  15. string description = sSiteName + " Site Testing";
  16. string type = System.Configuration.ConfigurationSettings.AppSettings["SiteTemplateId"];
  17.  
  18.  
  19.  
  20. // Site creation with unique permissions
  21. SPWebCollection webs = web.Webs;
  22. SPWeb newWeb = webs.Add(url, title, description, 1033, type, true, false);
  23.  
  24.  
  25. newWeb.Navigation.UseShared = true;
  26.  
  27. //Adds to site navigation
  28. SPNavigation nav = newWeb.ParentWeb.Navigation;
  29. SPNavigationNode node = new SPNavigationNode(newWeb.Title, newWeb.ServerRelativeUrl);
  30. node = nav.AddToQuickLaunch(node, SPQuickLaunchHeading.Sites);
  31.  
  32. //Adds to top quick link
  33. SPNavigationNodeCollection topnav = web.Navigation.TopNavigationBar;
  34. node = topnav.AddAsLast(node);
  35.  
  36. // Changing the request access email to current user
  37. newWeb.RequestAccessEmail = newWeb.CurrentUser.Email;
  38.  
  39. // Save changes
  40. newWeb.Update();
  41.  
  42. newWeb.Close();
  43. // Disposing new web object
  44. //newWeb.Dispose();
  45. }
  46. catch (Exception ex)
  47. {
  48. throw ex;
  49. }
  50. finally
  51. {
  52. web.AllowUnsafeUpdates = false;
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement