In the moss management interface, we can easily create a website. However, in some cases, dynamic, Program Create a website. This article demonstrates how to use winform on the client to create a moss website. The main functions are as follows:
1. Use a specific template to create a website
2. assign a super administrator to the new website
3. Activate a feature when creating a website
4. Add a link to the new website on the home page.
5. delete a specified website
For some basic operations, such as connecting to the moss site in winform, if you have any questions, refer to the first several articles in this series.ArticleI will not list them here
1. Use a specific template to create a website
Creating a template in Moss is relatively simple: first, you can customize a website and then export it as a template in website management.
Create a specified Template Code As follows: Spweb mysite = _ Sitecollection. openweb ( " / " );
Spwebcollection subsites = Mysite. webs;
Spwebtemplate mywebtemplate = Null ;
// Get Template
// Obtain the system template _ sitecollection. getwebtemplates (2052 );
// Get custom templates
Foreach (Spwebtemplate webtemplate In _ Sitecollection. getcustomwebtemplates ( 2052 ))
{
If (Webtemplate. Title = " Test " )
{
Mywebtemplate=Webtemplate;
Break;
}
}
String Siteurl = Textbox1.text. tostring (); // Relative Path, excluding/
String Sitetitle = Textbox2.text. tostring ();
String Sitedescription = Textbox3.text. tostring ();
Subsites. Add (siteurl, sitetitle, sitedescription, 2052 ,
Mysite. webtemplate,
True , // True: use independent permissions and do not inherit from the parent site.
False // False: an error occurs when the specified directory exists.
);
Because we use a custom template, we use the getcustomwebtemplates method. The 2052 parameter represents a template in Chinese. The custom template name is "test ", for other notes, you can refer to the comments in the Code. In particular, the siteurl parameter is only the relative path of a site. It cannot contain "/" or be written as http: // domain: 800/AAA/format
2. assign a super administrator to the new website
The Code is as follows: // Configuration Administrator
Spweb newsite = _ Sitecollection. openweb ( " / " + Textbox1.text + " / " );
Spusercollection users = Newsite. allusers;
For ( Int I = 0 ; I < Users. Count; I ++ )
{
Users. Remove (I );
}
Users. Add ( " Domain \ Username " , "" , "" , "" );
// Grant permissions to users
Sproledefinitioncollection roles = Newsite. roledefinitions;
Sproledefinition role = Roles [ " Full Control " ];
Spuser user = Users [ " Domain \ Username " ];
Sproleassignment rauser = New Sproleassignment (User );
Rauser. roledefinitionbindings. Add (role );
Newsite. roleassignments. Add (rauser );
1. First open the new website, delete all existing users, and then add a user;
2. Get the Role Definition of "full control"
3. Add a user to a role
4. assign a role to a website
3. Activate a feature while creating a website
feature is an important function in Moss, you must use feature to activate the flexible customization of moss. For example, you can add a link to the menu and an event (in moss SDK (5) mentioned in this article), you can also make an independent module into a feature and load it flexibly and dynamically (I am going to explain in the next article how to make an independent module into a feature,
the code here is quite simple, but I have been searching for it for half a day.-_- // activate a feature
newsite. features. add ( New GUID ( " 4292625e-5811-47a4-9b88-58a206c53515 " ));
The parameter here is the feature ID:<Feature
ID= "4292625e-5811-47a4-9b88-58a206c53515"
4. Add a link to the new website on the home page
After creating a sub-website, you must be able to see the following on the home page: // Add link to homepage
Spnavigationnodecollection topnav = Mysite. Navigation. topnavigationbar;
Topnav [ 0 ]. Children. addaslast ( New Spnavigationnode (textbox1.text, " / " + Textbox1.text ));
5. delete a specified website
This step is relatively simple. You can simply delete it.Spweb mysite=_ Sitecollection. openweb ("/");
Spwebcollection subsites=Mysite. webs;
Subsites. Delete (textbox4.text );
Appendix:
The demo interface is as follows:
DEMO code download: http://files.cnblogs.com/firstyi/MOSSClient8.rar