.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Programmatically create blog subsite

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :C#
public override void FeatureActivated(SPFeatureReceiverProperties properties)


   SPWeb web = (SPWeb)properties.Feature.Parent;



    web.Webs.Add("CommunityBlog", "Community Blog", "A blog for community sites", 1033, "BLOG#0", false, false);




    //write to logs




    //Free up resources




I have the code above in a feature receiver which is activated from my site definition. I don't receive any errors but when I create a new site collection based on my definition, no blog subsite is created. Is there a way to get the SPSite object without using SPContext, since it looks like it can't be used in a receiver?Any help would be appreciated.

View Complete Post

More Related Resource Links

Programmatically create an InfoPath form


I'm programmatically creating an InfoPath form using this article: http://www.bizsupportonline.net/infopath2007/programmatically-create-infopath-form-console-app.htm.


Everything works well up to 29 fields (my:field1 ... my:field29). After that it runs without an error and posts a form to the library however the icon does not switch to an infopath icon and the filename stays blanks. I don't believe this field specific, it seems to be happening when I use any 29 to 30 fields so I'm thinking its a memory issue with the stream reader.

Has anybody every had this issue before, is there a way to fix this?


how do i create a webpart for sharepoint 2010 that allows users to create their own subsite..



how do i create a webpart for sharepoint 2010 that allows users to create their own subsite..

for e.g..

i create a webpage in vs 2010 which allows users to create their account by specifying username and password..and make it a webpart and after that for that user a subsite should be created under sharepoint 2010 top level site.....how could i achieve that..

VS2008 and C#: How to create PictureBox controls programmatically in a FlowLayoutPanel ?

I am trying to create multiple PictureBox controls in a FlowLayoutPanel programmatically. The number of the PictureBox controls is dynamic depending on the target image folder. My current approach results a compilation error:             // (Works !)             pictureBox1 = new System.Windows.Forms.PictureBox();             pictureBox1.Width = 150;             pictureBox1.Height = 150;             flowLayoutPanel.Controls.Add(pictureBox1);             string sFileFullName = "Resources\\file1.bmp";             pictureBox1.Image = Image.FromFile(@sFileFullName);             // (Error !)             string pbName = "pictureBox";             for (int i = 0; i < 100; i++)             {             

how to create site collection by using custom template through programmatically?

hi all, how we can create site collection by using custom template through programmatically? please give me some suggestions. where we need to save this custom template... thanks in advance..

is there any problem if i create a site collection through programmatically which web application ha

hi all, My web application have 2  types of authentication -- for internal users (windows authentication) and external users (Form based authentication). I am creating site collections through programmatically in the web application. so this site collection should have the permission as form based authentication for external users and windows authentication for internal users. is it possible are not? please give me some suggestions on creating site collections which have form based authentication and windows authentication. thanks in advance......

how to create site collection by using custom template through programmatically?

hi all, how we can create site collection by using custom template through programmatically? please give me some suggestions. where we need to save this custom template... thanks in advance..

Cannot create unknown type '{clr-namespace:Blog.LongRunningWorkflow.Example.Activities}WaitForReques

Hi, I am facing problem in loading XAML at runtime. Below is the code please help me. public void ProcessRequest(Request request) { // Get the workflow instance id to use Guid instanceId = this.requestToInstanceMapping[request.Id];         // Setup the arguments that are passed to the workflow          IDictionary<string, object> input = new Dictionary<string, object>();              input.Add("Request", request);            using (FileStream fs = new FileStream(@"ProcessRequest.xaml", FileMode.Open))          {             // Load the ProcessRequest workflow           Activity wf = ActivityXamlServices.Load(fs) as Activity;                            // Create the workflow instance specifying the arguments and instance id                      WorkflowApplication wapp = new WorkflowApplication(wf, input);          string persistenceConnectionString = "Data Source=Dev1;Initial Catalog=InstanceStore;User id=sa;password=xxxxxxx;Asynchronous Processing=True";          &nbs

Create site template and adding subsite using site template is broken in sharepoint 2010

I am trying to create a site template base on an existing site and try to use the new site template to generate other sub-sites.  It sounds simple and the code is not that difficult to follow; however, Microsoft has made it impossible to accomplish by having a bug in their template creation process.   //Generate web template from existing website using (SPSite site = new SPSite("http://localhost")) { SPWeb web = site.OpenWeb("/barrington/accounting"); web.SaveAsTemplate("NewDepartmentTemplate", "NewDepartmentTemplate", "NewDepartmentTemplate", true); }   //Generate sub site using the new template using (SPSite site = new SPSite("http://localhost")) { SPWeb web = site.OpenWeb("/barrington/accounting"); SPWebTemplate tp = null; foreach (SPWebTemplate wt in web.GetAvailableWebTemplates((uint)1033)) { if (wt.Title == "NewDepartmentTemplate") { tp = wt; break; } } if (tp != null) { SPWeb newWeb = web.Webs.Add("NewDepartment", "NewDepartment", "NewDepartment", (uint)1033, tp, false, false); } } Error: Microsoft.SharePoint.SPException was unhandled   Message=The content type name '$Resources:_FeatureId367b94a9-4a15-42ba-b4a2-32420363e018,DataSourceContentTypeName;' cannot contain: \  / : * ? " # % < > { } | ~ & , two consecutive per

How do I create Sub-Categories under Categories in a Blog Site

Hello, Looking for help using a blog site I need to create sub-categories under Categories that are located  in the Quick Launch area and also be able to add to sub-categories when needed, plus click the sub-category and it will open the post under that sub-category. I hope that I am making sense.  Thank you so much, JAM

How to create a workflow programmatically?

Are there any samples that would show how to create and/or modify a workflow programmatically, i.e. from a program, not from VS.NET IDE or a hosted designer? For example, the program would create a new workflow, add a couple of activities to it, and save the serialized workflow definition (in a file or database). I can find examples explaining how to modify a workflow instance at run time, but I need to create a workflow definition, not the instance. Any hints? Thanks.Alek

Create list column, if column does not exist programmatically

Hi, I want to create a column in  the list programmatically. I tried this, and it created the column. But I would like to check if the list column already exist and if column does not exist, would like to create the column. How to check if a list column exists and if it does not exist, create the list column. I have used this code: [CODE] SPList MyList; MyList = currentweb.Lists[Constants.listname]; MyList.Fields.Add("FilesCount", SPFieldType.Number, false); MyList.DefaultView.ViewFields.Add("FilesCount"); MyList.DefaultView.Update(); [/CODE] Thank you

Is it possible to (re)create a variation's subsite?


Let's say I have two variation labels: NL(dutch) and EN (english) and NL is the Source Variation.

The main sites are working fine and the variations are linked correctly.

Now let's assume I have a subsite A, but somebody deleted the subsite A on the english variation. Is it possible to recreate this subsite without throwing away the entire variation label EN and then choose Create Hierarchies?

Thanks in advance!

Site Collection Admin Unable to create subsite


Hi All,

We are running into a wierd kind of problem, we had a site called A, A had to be split for two different user base so A was exported into B. Now we have two sites A & B with its own user groups.

Site collection admins of B are not able to create subsites in B. But site collection Admins of both A & B are able to create subsites in either sites.

if site collection admin of  B is given read/write control on Site A then he is able to create sites in B (totally wierd)

Can anybody help me identifying what is happening here and points to start our troubleshooting.  

Thanks in Advance,



Programmatically create a package... in silverlight?


I've succesfully managed to programmatically create and alter packages, but now I was wondering if it would be possible to do this in a fancy Silverlight 4 application.

Because you can't reference the Microsoft.SQLServer.ManagedDTS.dll assembly in Silverlight, I tried the AutomationFactory.CreateObject("ProgId") approach.

That's where I got stuck. What's the progid, and is this actually possible?

SlideLibrary programmatically create folder



I have created a workflow in visual studio 2010 for a slide library when i upload new slides that they get in a folder, if the folder doesn't excist the workflow will automatically create the folder and move the uploaded slide to the folder. I have a custom field "Folder name" that i use to enter a folder name where i can store the slides that i have uploaded.

The code that i use:

 SPListItem item = null;
 SPWeb web = null;
 string folderName = string.Empty;

 web = workflowProperties.Web;
 item = workflowProperties.Item;
 var name = item.Name.ToString();

      folderName = (string)item["Folder name"];
      if (folderName != string.Empty && folderName != null)

        SPFolder root = workflowProperties.List.RootFolder;

        string slideFolderUrl = SPUrlUtility.CombineUrl(root.ServerRelativeUrl, folderName);
        SPFolder slideFolder = web.GetFolder(slideFolderUrl);


Programmatically create publishing page and fill with content.


I have a bunch of HTML which has been exported from a different platform.
This HTML could be located in a database or contained within an HTML file. 

I am looking for some guidance on the best way to programmatically create a publishing page in SharePoint at a specific site location, then populating the RichHtmlField Publishing Web Control (PublishingPageContent) with the HTML that has been exported from one of the sources mentioned above.

Any suggestions/advice you can offer will be much appreciated.


Turn on publishing programmatically when a subsite is created


I have a Site Collection with Publishing Site Template. I would like to have the publishing turned on automatically whenever a non-publishing subsite is created. Upon searching, I found there are two options. one with site definition and another with feature stapler.

I am new to .NET coding. Any code references to implement the above solution would be helpful.

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend