Ebikeneser
Ebikeneser

Reputation: 2364

Get user name from application string

I have created a Silverlight business application, that require the user to login, and once they have, their user name is presented in the login status.

Located in the ApplicationStrings.resx is the following-

<data name="WelcomeMessage" xml:space="preserve">
  <value>Welcome {0}</value>
  <comment>{0} = User.DisplayName property</comment>
</data>

I am trying to get the user name of whoever has logged in from this, I have tried-

string userName = System.Convert.ToString(ApplicationStrings.WelcomeMessage);

However this brings the string backs as Welcome {0}.

Whereas what I actually need is the value of User.DisplayName property.

How can I get to that value?

Upvotes: 0

Views: 358

Answers (3)

Simon
Simon

Reputation: 5493

You need to use string.Format at the place where you retrieve the welcome message.

string userName = string.Format(ApplicationStrings.WelcomeMessage, WebContext.Current.User.DisplayName);

Upvotes: 2

Ebikeneser
Ebikeneser

Reputation: 2364

I did it by -

string userName = WebContext.Current.User.DisplayName;

Upvotes: 2

Oscar Jara
Oscar Jara

Reputation: 14187

Try to use string.Format for {0} recognition.

Upvotes: 0

Related Questions