Hey! Use A Method To Get Your SPList!
Well, maybe it is just me, but you should generally use a method in order to get a reference to your SharePoint lists. For example, you are generally getting a reference as such:
-
{
-
using(SPWeb myWeb = mySite.OpenWeb())
-
{
-
SPList myList = myWeb.Lists["MyList"];
-
}
-
}
But wouldn't it be better to use a method?
-
public static SPList GetList(SPWeb website, string listName)
-
{
-
if (website == null)
-
{
-
return null;
-
}
-
try
-
{
-
return website.Lists[listName];
-
}
-
catch
-
{
-
return null;
-
}
-
}
You could then use this between your setting of your web references. I think it is a much better, much more elegant approach when getting a reference to a list, but hell, maybe it's just me :-)
Related posts:
- Using Regular Expressions To Build SPList Collections
- Get SPList By URL In C#
- Returning Site Directory SPList
- SPListItem.URL Funky Return Fiesta
- Testing Whether A User Has SPBasePermission On SPList Object
No Comments »
No comments yet.
RSS feed for comments on this post. TrackBack URL























Articles & Research
SharePoint Architecture
Research Methodology
Personal/Off-Topic
Article Or Research Filed Under 
