There will be times when you will need to get a SharePoint list’s ID number. You might want to reference it in a look up field or work with it in some other coding example.
There’s a couple of ways to do this:
1. If you’re inside Visual Studio, you can always use the Lists.asmx web service to expose the parameters of the list you work on. Create an XML node and map it to the GetListAndView that is exposed by the Lists.asmx web service. The following illustrates:
Application.ListsWebService.Lists ListWebService = new ListsWebService.Lists(); //instantiate the web service
ListWebService.Credentials = System.Net.CredentialCache.DefaultCredentials; //provide access credentials
ListWebService.Url = “http://serverName/sites/siteName/_vti_bin/Lists.asmx”; //provide the URL of the webiste where the list is stored in
XmlNode myListView = ListWebService.GetListAndView(“Customers”, “”);//get the ListAndView node
strListID = myListView.ChildNodes[0].Attributes[“Name”].Value;//map the List ID to a string variable
2. A much easier approach is to get the GUID from the client. The List GUID is actually being displayed in the URL field of the list. It is however being URL Encoded so you’ll have to work around the encoding. However, there’s an even easier way, if you just dig a bit deeper. Locate the list, click on properties and then, click on “Audience targeting settings” under the “General Settings” column on the left. As soon as the page loads (it takes a bit), notice the URL! The GUID is displayed in “{}” unencoded. You can just select that number and copy it. That’s your list’s GUID. It will be something like this: http://serverName/sites/siteName/_layouts/ListEnableTargeting.aspx?List={6e5edcc1-ad6a-4767-bf1d-b49efca90103}
3. Just in case one of the upcoming service packs changes the displayed URL into one that has been URL Encoded, it’d be a good idea to know how to change a URL Encoded GUID into simple text. If for example you look at the URL of your list settings, you’ll be seeing something like this: http://sereverName/sites/siteName/_layouts/listedit.aspx?List=%7B6E5EDCC1%2DAD6A%2D4767%2DBF1D%2DB49EFCA90103%7D where the last part, the one that is in bold, is the URL Encoded GUID of your list.
So how do you turn %7B6E5EDCC1%2DAD6A%2D4767%2DBF1D%2DB49EFCA90103%7D into {6e5edcc1-ad6a-4767-bf1d-b49efca90103}.
You need to replace “%7B” with “{“, “%2D” with “-” and “%7D” with “}”
Great Post!!1 Thank YOu. Not much help was available on retrieving the GUID number dynamically.
Glad you found this helpful Praveena.
[…] use the following URL, you need to go fetch your list’s GUID. In case you do not know how to get a SharePoint 2010 List GUID follow the previous […]