In this blog you will see how to delete the list using web service.
Steps Involved:
1. Open Visual Studio 2010 by going Start | All Programs | Microsoft Visual Studio 2010 | Right click on Microsoft Visual Studio 2010 and click on Run as administrator.
2. Go to File tab, click on New and then click on Project.
3. In the New Project dialog box, expand the Visual C# node, and then select the Windows node.
4. In the Templates pane, select Console Application.
5. Enter the Name as WebServices and then click OK.
6. In the solution explorer, right click on the solution and then click on Properties.
7. Select the Application tab, check whether “.Net Framework 3.5” is selected for Target Framework.
8. Select the Build tab, check whether “Any CPU” is selected for Platform Target.
9. In the solution explorer, right click on the References folder and click on Add Reference.
10. Add the following reference.
1. Microsoft.SharePoint.dll
11. Right click on References folder and then click on “Add Service Reference”.
12. In the “Add Service Reference” wizard click on “Advanced...” button.
13. In the “Service Reference Settings” wizard click on “Add Web Reference...”.
14. In the URL section, enter the lists web service url (http://serverName/_vti_bin/lists.asmx) and then click on enter.
15. Enter the Web Reference Name and then click on “Add Reference” button.
16. Click on Ok.
17. Web Reference will be added successfully.
18. Double click on Program.cs and add the following Namespaces.
1. using Microsoft.SharePoint;
2. using System.Net;
3. using WebServices.ListServiceReference.
19. Replace Program.cs with the following code snippet.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint; using WebServices.ListServiceReference; using System.Net; namespace WebServices { class Program { static void Main(string[] args) { string listName="List Code"; Lists listReference = new Lists(); listReference.Url = "http://serverName10:10736/sites/ECT/_vti_bin/lists.asmx"; listReference.Credentials = CredentialCache.DefaultCredentials; listReference.DeleteList(listName); Console.WriteLine(listName + " list is deleted successfully"); Console.ReadLine(); } } }
|