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(SPSite mySite = new SPSite("http://server/"))
- {
- 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 :-)
Articles & Research
SharePoint Security
SharePoint Development
SharePoint Architecture
Claims Authentication
Forefront For SharePoint
AIS / Dynamics GP
Team Foundation Server
Pex And Moles
ISA/TMG/IAG/UAG
DPM
Cardspace
Research Methodology
Rural ICT Development
Numerical Analysis
Multi-Level Research
Knowledge Management
Personal/Off-Topic