There are some different ways to access a list in SharePoint 2010 by code. You can look at these SPWeb members in this msdn article. But i’d like to provide you two different ways here to get your list with c#.
In both cases you have to define your web:
SPWeb myWeb = SPContext.Current.Web;
1) Get list by Display Name
SPList myList = web.Lists[“ListDisplayName”];
This option has to be taken carefully, cause what happens if the lovely enduser changes the title of the list? It will change the displayname of the list and your code will not find the list, right?
So i prefer option 2 which gets the list by url. The url does not change even if the enduser gives the list a curios name and is happy with the name.
So how to get this by url?
2) Get list by URL
SPList myList = myWeb.GetList(SPUrlUtility.CombineUrl(myWeb.ServerRelativeUrl, “/Lists/ListUrlName”);
With this line, it doesn’t matter what list title you choose or display name the list had and will have in future, you don’t have to update code cause you updated your listname!
In this blogpost you’ll find some more helpful words.
..:: I LIKE SHAREPOINT ::..