The Share Point site is in Forms authentication. To Create the blog site
public void CreateSite(string strSiteURL,string strSiteTitle)
{
//Create a new SPSite object corresponding to your top level site
SPSite newSite = new SPSite(“http://moss/site”);
//Create a new SPWeb object from the newSite object
SPWeb newWeb = newSite.OpenWeb();
//Return the collection of sub sites
SPWebCollection subSites = newWeb.Webs;
If the site is blog site the template id is "Blog#0"
SPWeb newSubWeb = subSites.Add(“newsite”, “New Site”, “This is the description for my new site.”, 1033, “Blog#0”, true, false);
}
Remember it works in windows authentication, but it fails in forms authentication.
Because forms authentication doesn't have the enough authentication to create a site. It should be Impersonated with windwos credentials.
- go to central administration ->application management ->Create or Extend Web Application
- click on 'Extend an existing Web application' select the web application for which you enabled forms authentication.create a new IIS Website with zone as Intranet. for ex: http://systemname:1234/
- create an Asp.net webservice(for ex: myService) project and map it to the virtualdirectory of the above port.
- http://systemname:1234/myService.
- In the webservice Paste the above method.
- Add this webservice from asp.net application/webpart as below
- If the webreference is CustdomSite then the code as follows
- The code in asp.net application
- Public void CreateSite()
{
CustdomSite obj=new CustdomSite ();
System.Net.NetworkCredential cred = new NetworkCredential(UserName,Password,Domain); [Import system.Net namespace]
obj.Credentials=System.Net.CredentialCache.DefaultNetworkCredentials;
obj.CreateSite(txtsiteUrl.Text,txtSiteName.Text);
}
Assuming the user knows the Creation,deployement of custom webparts - Important Note: Most of the Object model functionalities in Forms authentication one needs to follow the above process.