tags:

views:

810

answers:

5

I am using the following code to programatically create a web application & sub site,

            try
            {

                SPWebApplicationBuilder webAppBuilder = new SPWebApplicationBuilder(SPFarm.Local);

                SPWebApplication newApplication;
                int myPort = 3333;
                webAppBuilder.Port = myPort; //Port No.
                webAppBuilder.RootDirectory = new System.IO.DirectoryInfo("C:\\Inetpub\\wwwroot\\wss\\VirtualDirectories\\" + myPort);
                webAppBuilder.CreateNewDatabase = true; // Create new database

                webAppBuilder.DatabaseName = "WSS_Content_372772890a5a4a04abb460cd9ea3bd22";    // Database name
                webAppBuilder.DatabaseServer = webAppBuilder.DefaultZoneUri.Host;  // DatabaseServer Host name/computer name          

                webAppBuilder.UseNTLMExclusively = true;  // Use NTLM authentication

                newApplication = webAppBuilder.Create(); // Create new web application
                newApplication.Provision();           // Provision it into web farm           

                using (var mySiteCollection = newApplication.Sites.Add("/", "Site 3", "Site 3 Decscription", 1033, "STS#1", "In-Wai-Svr2\\Administrator", "Administrator", "[email protected]"))
                {
                    using (var rootWeb = mySiteCollection.RootWeb)
                    {                        
                        // Code customizing root site goes here                        

                        using (var subSite = rootWeb.Webs.Add("Site3.1", "Site 3.1", "Site 3.1 Description", 1033, "STS#1", true, false))
                        {                            
                            // Code customizing sub site goes here
                        }                        
                    }
                }
            }
            catch(Exception ex)
            {
                ;
            }

It works fine i.e. it creates the web application on the specified port with sub site but this sub site will not be shown under Sites menu of Quick launch bar also it will not be shown as a separate tab on the Home Page. Is it possible to do it programatically?

+1  A: 

IS this the answer you are looking for?

example

Colin
A: 

Colin,

Actually using the above code I want to write a utility which will create a web application on the production server of my client. Client requirement is to use this utility ti install on any production server. So I have just began to write & found that using above code it creates the web application but the sub site does not appear as a separate tab on the home page. If you have any helpful information similar to this scenario please post it.

Tejas
A: 

"web application but the sub site does not appear as a separate tab on the home page"

I think that what you are trying to acomplish is to create a new website, inside the same application, for that you can't create a new application because it will create a new pool of sites. You have to create a new "sub"website inside the same application your home site is.

hope this helps: example

v3ga
A: 

Hi v3ga,

Thanks for the reply, but I am not understanding what you are trying to say. I will explain you in detail. I have started writting a utility which will create a wss web site for me or my client by providing appropriate and well defined xml file as a input using sharepoint object model. Some sample code is as as above.

I asked myself a question --> How do I create a web application using SharePoint Administration? I Answared --> First I create a new web application named Temp, now It will ask me for Create Site Collection, I will create a site collection, now this site collection is nothing but a root site or top level of site for me and when I login to this newly create site I see a Home Tab which is for root site i.e. Site collection Now inside it I will create a SubSite named Temp1 this sub site will appear just next to Home Tab.

Same type of functionality I am trying to do using sharepoint object model but the problem is sub site gets created but it will not be shown as a seperate Tab next to Home tab, if I click on Sites menu in Quick launch bar it shows the newly created sub site.

Please provide me the solution on it. May be I am not understanding what you are trying to say so please explain me in detail if possible.

Thanks, Tejas Jagtap

Tejas
A: 

Hi Tejas ...Nishikant Here !! Nice to see you here man...

nishikant