Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Is there a way in Sharepoint 2007 Publishing, to retrieve a custom content type's column value for the displayed article. I want to show different colored ribbon images according to article type which is stored in a custom column.

Thank you.

share|improve this question

3 Answers 3

If you place a FieldValue control on a Page Layout you can set this to display the value of a custom column using the FieldName property. For example:

<SharePointWebControls:FieldValue FieldName="CustomFieldName" runat="server"/>

Note you will need a reference to Microsoft.SharePoint.WebControls at the top of the page before this will work e.g.

<%@ Register Tagprefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 

If you need to perform some manipulation on this value then you can get the value in code by using SPContext.Current.ListItem["CustomFieldName"].

share|improve this answer

For a publishing page to get the column value I use the following

This code i have written in a UserControl Placed in a Page Layout , and in the UserControl i wrote the following code

using Microsoft.SharePoint;
using Microsoft.SharePoint.Publishing;
using Microsoft.SharePoint.Publishing.WebControls;
using Microsoft.SharePoint.Publishing.Fields;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebControls;

 PublishingPage currentPage = PublishingPage.GetPublishingPage(SPContext.Current.ListItem);

if (currentPage != null)

                {
                    string title= currentPage.ListItem["Title"].ToString(); ;

                }
share|improve this answer

I used the folowing method to get the data from all publishing pages that have value in the "Page Content" field

            using (SPSite site = new SPSite("[site collection url]"))
            {
                using (SPWeb web = site.OpenWeb("/[Subsite]/"))
                {
                    PublishingWeb myWeb = PublishingWeb.GetPublishingWeb(web);
                    PublishingPageCollection pages = myWeb.GetPublishingPages();

                    foreach (PublishingPage page in pages)
                    { 

                        if (page.Title == pageTitle)
                        {
                            if (page.ListItem["Page Content"] != null)
                                    Label2.Text = page.ListItem["Page Content"].ToString();
                                else
                                    Label2.Text = "The page " + page.Title.ToString() + " does not have content in ...Page Content... section";
                        }

                    }                
                }
            }   

hope it helps.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.