private void GetListAndView()
{
// We open the SPList
Guid siteID = SPContext.Current.Site.ID;
Guid webID = SPContext.Current.Web.ID;
using (SPSite site = new SPSite(siteID))
{
using (SPWeb web = site.OpenWeb(webID))
{
// We get the list from its name
try
{
_list = web.Lists[_listName];
}
catch
{
throw (new Exception("The list name your provided does not exist or cannot be found"));
}
// We get the view from its name or get the default one
if (_viewName != String.Empty)
{
try
{
_view = _list.Views[_viewName];
}
catch
{
throw (new Exception("The view name your provided does not exist or cannot be found"));
}
}
else
{
_view = _list.DefaultView;
}
}
}
}