Sitefinity ASP.NET CMS - Content Management System

Support Forum Thread

Home >  Support >  Forums home > Sitefinity 3.x > Modules > Display username as news author

Reply
Szymon, 7/14/2008 2:39:27 AM
Hi,
I would like to display the name of the user that created the news as its author. Currently the template uses the Author metafield. How I can change it to use the Creator name instead? Or how to change the system to initialize the Author with logged in user name when creating new news item?

Regards,
Szymon

Reply
, 7/16/2008 5:26:12 AM
Hi Szymon,

You can set the Author metafield dynamically with the Sitefinity's APIs.

This could be done with a few lines to global.asax file, located in your project's bin directory:

void Application_Start(object sender, EventArgs e)  
   //Event handler catching the Content Manager executing
   Telerik.Cms.Engine.ContentManager.Executing += new EventHandler<Telerik.ExecutingEventArgs>(ContentManager_Executing); 
 
void ContentManager_Executing(object sender, Telerik.ExecutingEventArgs e) 
    //Check whether the user is creating content 
    if (e.CommandName == "CreateContent"
    { 
        //take the IContent Item from the command arguments 
        Telerik.Cms.Engine.IContent cnt = e.CommandArguments as Telerik.Cms.Engine.IContent; 
        //chech if there is such content and if it belongs to the news provider 
        if (cnt != null && cnt.ProviderName == "News"
        { 
            //get the current user's First and Last names 
            ProfileBase profile = ProfileBase.Create(HttpContext.Current.User.Identity.Name); 
            string FirstName = profile.GetPropertyValue("FirstName").ToString(); 
            string LastName = profile.GetPropertyValue("LastName").ToString(); 
            //Save these to the Author Metafield. 
            cnt.SetMetaData("Author", FirstName+" "+ LastName); 
        } 
    } 

I have included some comments.

In addition, you may also check whether the user has first or last name, or if there's already something written in the Author's field.

I hope this helps.

All the best,
Georgi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center

Reply
Szymon, 7/16/2008 9:01:52 AM
Hi Georgi,

Thanks for your response - this solves my problem!

I also noticed that there is also possible to set the default value for metafields in web.config. For example this is for the Publication_date

<add key="News.Publication_Date" valueType="DateTime" visible="True" searchable="True" sortable="True" defaultValue="#Now" />

Difference is that these valus are applied already when user enters the create news page, where with your solution it is applied on save. Would be great if you could add a shorthand for the user name that could be used here as well. Or maybe some simple expression minilanguage to combine several fields like you did with the FirstName and LastName from user profile.

Thanks!
-Szymon


Reply
, 7/17/2008 11:33:49 AM
Hi Szymon,
/* tfs 14543 */
We are adding this suggestion to our Feature Requests list right away. The suggestions are always welcome, and we will definitely discuss yours.

Thank you!

Regards,
Georgi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center