Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Where can I find the id of my list created in Visual Studios. I've created a list with "add new item"-> list. But now I need to have the ID of that list. I can't find it anywhere. What should I do?

share|improve this question

1 Answer 1

up vote 8 down vote accepted

You can find list template ID in Visual studio by looking at Schema.xml but you won't going to find list ID.

To get list ID you can use this code in VS,

localhost.Lists ls = new WebApplication3.localhost.Lists(); 
ls.Credentials = new System.Net.NetworkCredential("sunil", "password"); 
ls.Url = "http://mossserver/_vti_bin/Lists.asmx"; 
var lsturl = ls.GetList("Tasks"); XmlNode node = ls.GetListAndView("Tasks", ""); 
string sListID = node.ChildNodes[0].Attributes["Name"].Value; 
string sViewID = node.ChildNodes[1].Attributes["Name"].Value; 

Or you can try this simple code,

using(SPSite site = new SPSite("URL to List"))
using(SPWeb web = site.openweb())
{
    SPList list = web.Lists["List Name"];
    Console.WriteLine(list.ID.ToString());
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.