SharePoint: Use C# or CAML to read contact person (etc) for current page.

Posted on 2011-10-21
Last Modified: 2012-05-12
I created custom web-part.  How can I read  (C# or CAML) contact person (i.e) for current page? This information would allow me to customize web part / send email and so on.
Question by:tolppa
    LVL 18

    Expert Comment

    Hi! Do you mean information from contact webpart?
    LVL 1

    Author Comment

    My problem is very simple one. Basically I need to query information from current page / site. Lets say I have custom content type X with fields a, a, c. How do I query column a? How do I query Contact Person(?) field user is needed to to fill when new site is created.
    LVL 18

    Accepted Solution

    Hi! Then I guess you want to get PublishingContact field of the current publishing page. Try this:

    SPFile file = SPContext.Current.Web.GetFile(HttpContext.Current.Request.A
    string pageFile = pubWeb.GetFile(.Current.Request.Url.ToString());
    SPListItem pageItem = pageFile.Item;
    SPField field = pageItem.Fields.GetFieldByInternalName("PublishingContact");
    object objValue = pageItem[field.Id];
    SPFieldUserValue contactValue = objValue != null ? new SPFieldUserValue(SPContext.Current.Web, objValue.ToString()) : null;

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Summary In SharePoint 2010 it is easy to create custom color themes to jazz up a site. Theme colors can also be created in PowerPoint 2010 with a few clicks. But how do the chosen colors actually look in the SharePoint site? The attached PowerPoint…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    This video discusses moving either the default database or any database to a new volume.

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now