以编程方式创建Web应用程序&子网站

时间:2009-06-12 07:18:56

标签: sharepoint

我正在使用以下代码以编程方式创建一个Web应用程序&子网站,

            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", "tjagtap@waiin.com"))
                {
                    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)
            {
                ;
            }        

它工作正常,即它在具有子站点的指定端口上创建Web应用程序,但此子站点不会显示在快速启动栏的“站点”菜单下,也不会在主页上显示为单独的选项卡。是否有可能以编程方式进行?

2 个答案:

答案 0 :(得分:0)

“网络应用程序,但子网站不会在主页上显示为单独的标签”

我认为您想要实现的是在同一个应用程序中创建一个新网站,因为它无法创建新的应用程序,因为它将创建一个新的网站池。您必须在您的主站点所在的同一应用程序中创建一个新的“子”网站。

希望这会有所帮助: example

答案 1 :(得分:0)

SharepointSiteService.Sites siteWS = new SharepointSiteService.Sites();
                                siteWS.Credentials = new System.Net.NetworkCredential("user1", "password", "domain");
try 
{

                                            SharepointSiteService.Template[] templates;
                                            siteWS.GetSiteTemplates(1033, out templates);
                                            SharepointSiteService.Template template = (from SharepointSiteService.Template t
                                            in templates
                                                                                       where t.Title == "Test Template"
                                                                                       select t).FirstOrDefault();

siteWS.CreateWeb("<parent web name>" + "/" + <sub web name>" + "/" + <sub web name>", "Test web", "Test Web", template.Name, 1033, true, 1033, true, 1033, true, false, false, false, false, false, false); 
}
catch (Microsoft.SharePoint.SoapServer.SoapServerException e)
{
                                        System.Diagnostics.EventLog.WriteEntry("SharePoint Foundation", "soap exception" + e.Detail + e.Message + e.Source + e.Node);
}
catch (Exception ex)
{
                                        System.Diagnostics.EventLog.WriteEntry("SharePoint Foundation", "Site Created");
                                        System.Diagnostics.EventLog.WriteEntry("SharePoint Foundation", ex.Message + ex.Source + ex.StackTrace);
 }`enter code here`