Show 'Display Name' defined in profile instead of login ID on the posting author

Topics: ASP.NET 2.0, Controls
Jul 16, 2008 at 5:25 AM
Hi,

Does anyone notice the current display author name on each posting is refer to the login ID instead of the defined 'Display Name' under the profile detail? I would like to made a change on this, but I am new in theBlogEngine.Core.dll source code. So, appreciate someone can share the experience wit me.

Cheers,
Hackzai
Jul 16, 2008 at 5:54 AM
Hi,

I just work out my solution and it just need a minor update on the BlogEngine.Web\admin\Pages\Add_entry.aspx.cs file as below,

The original BindUser function code is 

   private void BindUsers()
   {
      foreach (MembershipUser user in Membership.GetAllUsers())
      {
            ddlAuthor.Items.Add(user.UserName);
      }
  }

Change to the following code,

   private void BindUsers()
   {
      foreach (MembershipUser user in Membership.GetAllUsers())
      {
         AuthorProfile pc = AuthorProfile.GetProfile(user.UserName);
         if ((pc != null) && (pc.DisplayName.Length > 0))
            ddlAuthor.Items.Add(pc.DisplayName);
         else
            ddlAuthor.Items.Add(user.UserName);
      }
  }


Cheers,
Hackzai
Jul 16, 2008 at 7:54 AM
Oops, just notice I was missed out the code to update the selected author from the list when start a new post on BlogEngine.Web\admin\Pages\Add_entry.aspx.cs


Below is the original code,

   private void PreSelectAuthor(string author)
   {
      ddlAuthor.ClearSelection();
      foreach (ListItem item in ddlAuthor.Items)
      {
         if (item.Text.Equals(author, StringComparison.OrdinalIgnoreCase))
         {
             item.Selected = true;
             break;
         }
      }
   }

A new extra line of code to read the current login user's display name from the profiler, and the new code is show in below.

   private void PreSelectAuthor(string author)
   {
      AuthorProfile pc = AuthorProfile.GetProfile(author);
      if ((pc != null) && (pc.DisplayName.Length > 0)) author = pc.DisplayName;

  
      ddlAuthor.ClearSelection();
      foreach (ListItem item in ddlAuthor.Items)
      {
         if (item.Text.Equals(author, StringComparison.OrdinalIgnoreCase))
         {
             item.Selected = true;
             break;
         }
      }
   }

Coordinator
Jul 16, 2008 at 9:01 AM
A Post now have a AuthorProfile property where you can get the info you need.