Profile

Cover photo
Rich Ross
Works at ePharmaSolutions
Attended Pennsylvania State University
Lives in Wallingford, PA
57 followers|18,944 views
AboutPostsPhotosVideos

Stream

In his circles
78 people
Have him in circles
57 people
Wasi Khan's profile photo
Jen Mudd's profile photo
Andrew Beno's profile photo
paul keijzers's profile photo
MOE Gates's profile photo

Rich Ross

Shared publicly  - 
 
ItemFieldIterator: Display Content from Different Web

The List Fields Iterator control provides an easy way to present list information dynamically on your page. Just point it to the ListId, set the control mode to New or if the item exists, Display or Edit while setting the ItemId. You do not need to know the names of the columns in your list, unless you do not want to display. This works great provided the list and the page are on the same SPWeb. The ListFieldIterator does have a Web property, but this is a Get or Read-only property, so there was no way to directly set this on the control. However, you can indirectly set it.

The ListFieldIterator contains a property called ItemContext. This property can be set with an SPContext object during the Page_Init method of the application page. There are a number of overloads for the SPContext.GetContext method and you can see them here. I picked the one that worked best for my scenario., which in this case is am SPWeb and ListId in my context.



using (SPSite oSPSSite = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb oSPWeb = oSPSSite.OpenWeb(string.Concat(oSPSSite.ServerRelativeUrl, "/mySite")))
{
Guid ListId = oSPWeb.GetList(string.Concat(oSPWeb.ServerRelativeUrl, "/", ListUrl)).ID;
NewDocumentItem.ItemContext = SPContext.GetContext(Context, 0, ListId, oSPWeb);
}
}



This is now the only property I needed to set for the control. I was setting the list id and item properties on the ListFieldIterator when the list was on the same SPWeb. The context now handles this. In working with this control, it looks like setting the list and item properties in addition to the ItemContext property confused the ListFieldIterator. It seemed to forget the ItemContext property and try to resolve the ListId based on the SPContext.Current properties.

One other note is that if you are saving new or updated information to the list, you will need to run the new or update code inside the SPSecurity.RunWithElevatedPriviledges block. This is because this portion of the page has a different context than the Form tag on the page, which is a security issue.
1
Add a comment...
People
In his circles
78 people
Have him in circles
57 people
Wasi Khan's profile photo
Jen Mudd's profile photo
Andrew Beno's profile photo
paul keijzers's profile photo
MOE Gates's profile photo
Education
  • Pennsylvania State University
    BS Biology
  • Thomas Jefferson University
    MS Microbiology
Basic Information
Gender
Male
Work
Occupation
Sr. SharePoint Solution Architect
Employment
  • ePharmaSolutions
    Associate Director, System Configurations, 2010 - present
  • Sanofi-aventis
    IT Project Manager, 2006 - 2010
  • Merck
    1996 - 2006
Places
Map of the places this user has livedMap of the places this user has livedMap of the places this user has lived
Currently
Wallingford, PA
Previously
Ridley Park, PA
Links
YouTube
Other profiles
Contributor to