Referencing site content columns from within Layout page

I would like to inherit a display control in SP (for example... URLField) and then render content that references columns from that page's Site Content. This appears that it should be easy to code, but I have not been able to run across any examples of how the columns are referenced.

Thanks for any help in advance.

Tom

[341 byte] By [SharePointTom] at [2008-1-1]
# 1

if you can get the page's SPItem object, it is simple, the trick is to get the SPItem for the current page.

Here are some pointers:

  1. When in a control you can get the current page url by using "this.Page.Request.Url.ToString()"

  2. using that url, you can get to the SPFile object:

    Code Snippet
    using (SPSite site = new SPSite(this.Page.Request.Url.ToString()))
    {
    using (SPWeb web = site.OpenWeb())
    {
    SPFile file = web.GetFile(this.Page.Request.Url.ToString());
    }
    }

  3. using the SPFile object you can get to the SPItem:

    Code Snippet
    SPListItem item = file.Item;

  4. using the SPItem object you can change the properties (columns):

    Code Snippet
    item["My Column"] = "This is my value";
    item["Title"] = "This is my new Title";
    item.Update();

  5. If you want to get the values:

    Code Snippet
    string myValue = item["My Column"].ToString();
    string myTitle = item["Title"].ToString();

IshaiSagi at 2007-9-7 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...

SharePoint Products and Technologies

Site Classified