Wss3sdk: how to create or delete a list

Source: Internet
Author: User
You can use Splistcollection Class Add Method To create a list.
The following example creates a general list, calendar, or notification based on user input. The switch statement is used to set a list template based on the list type entered by the user.

Note::
In this example, Microsoft. Sharepoint. spcontent class members are used to obtain the current website set, website, and list. In addition to the HTTP context, such as in a command line application or a Windows application, this method cannot be used.
VB

Dim Mysite As Spweb = Spcontext. Current. Web
Dim Lists As Splistcollection = Mysite. Lists

Dim Listtitle As   String   = Textbox1.text
Dim Listdescription As   String   = Textbox2.text
Dim Listtype As   String   = Listbox1.selecteditem. Text

DimListtemplatetypeAs NewSplisttemplatetype ()

Select   Case Listtype
Case   " Generic list "
Listtemplatetype = Splisttemplatetype. genericlist
Exit  
Case   " Events "
Listtemplatetype = Splisttemplatetype. Events
Exit
Case   " Announcements "
Listtemplatetype = Splisttemplatetype. Announcements
Exit  
End   Select
Lists. Add (listtitle, listdescription, listtemplatetype)

C #Spweb mysite=Spcontext. Current. Web;
Splistcollection lists=Mysite. lists;

StringListtitle=Textbox1.text;
StringListdescription=Textbox2.text;
StringListtype=Listbox1.selecteditem. text;

Splisttemplatetype listtemplatetype= NewSplisttemplatetype ();

switch (listtype)
{< br> case " generic list " :< BR >{< br> listtemplatetype = splisttemplatetype. genericlist;
Break ;< BR >}

case " events " :
{< br> listtemplatetype = splisttemplatetype. events;
Break ;< BR >}

Case "Announcements":
{
Listtemplatetype=Splisttemplatetype. announcements;
Break;
}
}

Lists. Add (listtitle, listdescription, listtemplatetype );

CodeYou need to add a Microsoft. SharePoint namespace.
In this example,SplisttemplatetypeObject To store the list type specified by the user. This object isAddA required parameter of the method. The sample code assumes that there are two textbox for entering the title and description. In addition, a drop-down list is used to select the list type. In additionSplisttemplatetypeYou can also use the splisttemplate object to create a list.SpwebClassListtemplatesAttribute can be used to return a set of list template objects and specify the list template to be used by name index. The following example shows the implementation method. This example assumes that it is currently in a workspace website.

VB

Dim Mysite As Spweb = Spcontext. Current. Web

Dim Template As Splisttemplate = Mysite. listtemplates ( " Decisions " )
Mysite. Lists. Add ( " My decisions " , " This is a list of decisions " ,
Template)

C #

Spweb mysite = Spcontext . Current . Web;

Splisttemplate Template = Mysite . Listtemplates [ " Decisions " ];
Mysite . Lists . Add ( " My decisions " ,   " This is a list of decisions " ,  
Template );

This code must reference the Microsoft. SharePoint namespace.
In the following example, we can useSpsiteClassGetcustomlisttemplatesMethod to return to the custom list template in a specific site, and then we will create a list based on a specific list template.
VB

Dim Sitecollection As Spsite = Spcontext. Current. Site
Dim Mysite As Spweb = Spcontext. Current. Web

Dim Listtemplates As Splisttemplatecollection
= Sitecollection. getcustomlisttemplates (mysite)
Dim Listtemplate As Splisttemplate
= Listtemplates ( " Custom list template " )
Mysite. Lists. Add ( " Custom list " , " A list created from
A Custom List template In The list template catalog " , Listtemplate)

C #

Spsite sitecollection = Spcontext. Current. Site;
Spweb mysite = Spcontext. Current. Web;

Splisttemplatecollection listtemplates
= Sitecollection. getcustomlisttemplates (mysite );
Splisttemplate listtemplate = Listtemplates [ " Custom list template " ];
Mysite. Lists. Add ( " Custom list " , " A list created from
A custom list template In The list template catalog " , Listtemplate );

This code must reference the Microsoft. SharePoint namespace.
To delete a list, you mustDeleteSpecifies the guid of the list. You can useSplistClassIDThe GUID of the property.
VB

Dim Mysite As Spweb = Spcontext. Current. Web
Dim Lists As Splistcollection = Mysite. Lists

DimListAsSplist=Lists (textbox1.text)
DimListguidAsSystem. guid=List. ID

Lists. Delete (listguid)

C #

Spweb mysite = Spcontext. Current. Web;
Splistcollection lists = Mysite. lists;

Splist list=Lists [textbox1.text];
System. guid listguid=List. ID;

Lists. Delete (listguid );

This code must reference the Microsoft. SharePoint namespace.
This example has a textbox. You can specify the name of the list to be deleted.

Related Article

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.