Creating a List programmatically by using out of the box List Template Types
Dim site As SPSite = SPContext.Current.Site
Dim web As SPWeb = site.RootWeb
web.AllowUnsafeUpdates = True
Dim _listname As String = listname.Text
Dim listExist As Boolean = False
For Each list As SPList In web.Lists
If _listname.ToLower() = list.RootFolder.Name.ToLower() Then
listExist = True
Exit For
End If
Next
If listExist Then
Response.Write("List already Exist in site can not be created")
Else
web.Lists.Add(_listname, "listdescription", SPListTemplateType.Announcements)
Response.Write("List created")
End If
web.AllowUnsafeUpdates = False
Common OOTB List Templates For Reference
Events
Contacts Events
Tasks
PictureLibrary
DiscussionBoard
Survey
DocumentLibrary
Links
Document Library
Announcements
GenericList
WorkflowHistory
DataConnectionLibrary
DataSources
GanttTasks
CustomGrid
NoCodeWorkflows
XMLForm
WebPageLibrary
WorkflowProcess
Form Library
wiki
Wiki Page Library
Picture Library
DataConnectionLibrary
DataSources
GanttTasks
CustomGrid
NoCodeWorkflows
XMLForm
WebPageLibrary
WorkflowProcess
Form Library
wiki
Wiki Page Library
Picture Library
Picture
Contacts
Calendar
Discussion Board
Project Tasks
Issue Tracking
Custom List
Custom List in Datasheet View
Survey Survey
Custom Workflow Process
Languages and Translators
Translation Management Library
DataSources
Data Connection Library
Workflow History
No Code Workflows
Pass the Existence List name Using text box
Contacts
Calendar
Discussion Board
Project Tasks
Issue Tracking
Custom List
Custom List in Datasheet View
Survey Survey
Custom Workflow Process
Languages and Translators
Translation Management Library
DataSources
Data Connection Library
Workflow History
No Code Workflows
Create Sharepoint List Programmatically using an existing custom List Template
Dim site As SPSite = SPContext.Current.Site
Dim web As SPWeb = site.RootWeb
web.AllowUnsafeUpdates = True
Dim listTemplates As SPListTemplateCollection = site.GetCustomListTemplates(web)
Dim internalName As String = "email template.stp"
For Each _listtemp As SPListTemplate In listTemplates
If (_listtemp.InternalName.Equals(internalName)) Then
Dim template As SPListTemplate = listTemplates("email template")
Dim listId As Guid = web.Lists.Add("Asdf", "The new custom list", _listtemp)
Dim list As SPList = web.Lists(listId)
End If
Next
web.AllowUnsafeUpdates = False
Dim internalName As String = "email template.stp"
For Each _listtemp As SPListTemplate In listTemplates
If (_listtemp.InternalName.Equals(internalName)) Then
Dim template As SPListTemplate = listTemplates("email template")
Dim listId As Guid = web.Lists.Add("Asdf", "The new custom list", _listtemp)
Dim list As SPList = web.Lists(listId)
End If
Next
web.AllowUnsafeUpdates = False
Delete Sharepoint List Programmatically using Server object model
Dim site As SPSite = SPContext.Current.Site
Dim web As SPWeb = site.RootWeb
web.AllowUnsafeUpdates = True
Dim lists As SPListCollection = mySite.Lists
Dim list As SPList = lists(TextBox1.Text)
Dim listGuid As System.Guid = list.ID
lists.Delete(listGuid)
Dim web As SPWeb = site.RootWeb
web.AllowUnsafeUpdates = True
Dim lists As SPListCollection = mySite.Lists
Dim list As SPList = lists(TextBox1.Text)
Dim listGuid As System.Guid = list.ID
lists.Delete(listGuid)
Pass the Existence List name Using text box
The below code delete particular list from multiple website
Dim _site As SPSite = SPContext.Current.Site
Dim _allWebs As SPWebCollection = _site.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