Wss3sdk: how to add or delete a list from multiple websites

Source: Internet
Author: User
We can use Splistcollection Class Add Method to add a list to multiple websites in the website set.
The following example creates a general list in each website. The title and description of the list come from two textbox. Spsite Class Allwebs Property can be used to return the collection of all websites in the current site set.
This example is set to A. ASPX page that contains from with two textbox.
VB

Dim Listtitle As   String   = Textbox1.text. tostring ()
Dim Listdescription As   String   = Textbox2.text. tostring ()

dim mysite as spsite = spcontext. current. site
dim allwebs as spwebcollection = mysite. allwebs
dim Web as spweb

For EachWebInAllwebs
DimAlllistsAsSplistcollection=Web. Lists
Alllists. Add (listtitle, listdescription, splisttemplatetype. genericlist)
NextWeb

C #

String Listtitle = Textbox1.text. tostring ();
String Listdescription = Textbox2.text. tostring ();

Spsite mysite=Spcontext. Current. Site;
Spwebcollection allwebs=Mysite. allwebs;

Foreach(SpwebInAllwebs)
{
Splistcollection alllists=Web. lists;
Alllists. Add (listtitle, listdescription, splisttemplatetype. genericlist );
}

CodeYou need to add a Microsoft. SharePoint namespace.

If you want to delete a list from each website, you can useSplistcollectionClassDeleteMethod. The following code uses nested loops to find a list that matches the title and the content entered in the text box. This example is set to A. ASPX page containing from with a textbox.
VB

Dim Mysite As Spsite = Spcontext. Current. Site
Dim Allwebs As Spwebcollection = Mysite. allwebs
Dim Web As Spweb

for Each Web in allwebs
dim alllists as splistcollection = Web. lists
dim I as integer

for I = 0 to alllists. count - 1
dim List as splist = alllists (I)

If List. Title = Textbox1.text Then
Dim Listguid As Guid = List. ID
Alllists. Delete (listguid)
End   If
Next I
Next Web

C #

Spsite mysite = Spcontext. Current. Site;
Spwebcollection allwebs = Mysite. allwebs;

Foreach(SpwebInAllwebs)
{
Splistcollection alllists=Web. lists;

for ( int I = 0 ; I alllists. count; I + )
{< br> splist list = alllists [I];

If(List. Title=Textbox1.text)
{
Guid listguid=List. ID;
Alllists. Delete (listguid );
}
}
}

In this example,SplistClassTitleThis attribute is used to identify the list in the list of each website and determine whether it is the same as the specified title.IDProperty returns the unique identifier of the List (Guid), UsedDeleteParameters of the method.
You need to add a Microsoft. SharePoint namespace to the code.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.