Last active
December 26, 2015 10:49
-
-
Save xdumaine/7139388 to your computer and use it in GitHub Desktop.
utility method for resolving a ListFormWebPart on a custom page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in code behind (null checking/exception catching omitted for clarity) | |
var listItemId = int.Parse(Request["ID"]); | |
Utilities.ResolveListFormWebPart("MyListName", listItemId, MyListFormWebPart); | |
// in utilities class | |
internal static void ResolveListFormWebPart(string listName, int listItemId, ListFormWebPart listFormWebPart) | |
{ | |
using (var site = new SPSite(SPContext.Current.Web.Url)) | |
using (var web = site.OpenWeb()) | |
{ | |
var theList = web.Lists[listName]; | |
if (theList == null) | |
{ | |
throw new NullReferenceException(string.Format("The specified list '{0}' does not exist in the site '{1}'.", listName, SPContext.Current.Web.Url)); | |
} | |
listFormWebPart.ListId = theList.ID; | |
listFormWebPart.ListItemId = listItemId; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment