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:
C#:
-
{
-
using(SPWeb myWeb = mySite.OpenWeb())
-
{
-
SPList myList = myWeb.Lists["MyList"];
-
}
-
}
But wouldn't it be better to use a method?
C#:
-
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
No Comments »
No comments yet.
RSS feed for comments on this post. TrackBack URL





















Articles & Research
SharePoint Architecture
Personal/Off-Topic
Latest Free SharePoint Software
SecureCenter For SharePoint
SharePoint Security Assurance Program™
Free Online SharePoint Security Tools
Online SharePoint Security Health Assessment
Article Or Research Filed Under 