If you want to get hold of a SharePoint List by its ID, but only when the current user has access to it, there are many pitfalls. If you try to use SPListCollection.GetList, and plan to check the permissions after you get it, it’s too late. Your app will blow up and the user will get the “Access Denied” window.
web = OpenWebById(webId); if (web == null) return null; var listId = new Guid(myListId); // Return null if the current user does not have access // (and if list does not exist) web.Lists.ListsForCurrentUser = true; List<SPList> lists = web.Lists.Cast<SPList>().ToList(); if ((lists.Where(t => t.ID == listId)).Count() == 0) return null; // If we get to here, the user HAS access, so we can safely // use web.Lists.GetList() or alternatively web.Lists[listId] var list = web.Lists.GetList(listId, false);
Sometimes it’s easiest to solve SharePoint programming problems by going around them.
As always: Comments are welcome!