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.