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?
1 Answer
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());
}