The following function is used for getting a sharepoint page listitem based on the given URL. It returns an SPListItem for the page if found. If it returns null is the page is not found or the user doesn't have permissions to see it.
pageUrl - Page url to search and get the SPLisItem
context - The SPContext to use to retrieve the list item.
public SPListItem GetListItem(string pageUrl, SPContext context)
{ SPListItem page; try { using (SPWeb web = context.Site.OpenWeb(pageUrl, false)) { page = web.GetObject(pageUrl) as SPListItem; } } catch (FileNotFoundException) { page = null; } catch (ArgumentException) { page = null; } return page; }
catch(Exception ex)
{}
}
In the above function the parameters are,
pageUrl - Page url to search and get the SPLisItem
context - The SPContext to use to retrieve the list item.
Hope it helps.
No comments:
Post a Comment