Reputation: 537
I need to get Windows 8 app name to a variable, but I can't find a way to do this.
I want to get Title ("TEMEL UYGULAMA") from Application Properties, as shown in this screenshot: http://prntscr.com/psd6w
Or if anyone knows anyway to get application name or title, I can use it. I just need to get app name or title (inside the assembly)
Thanks for your help.
Upvotes: 0
Views: 917
Reputation: 5122
I use some code like this to get the Title
attribute of my Windows Store App assembly:
First, you need these assemblies:
using System.Reflection;
using System.Linq;
...and then code like this should work (with more checks maybe):
// Get the assembly with Reflection:
Assembly assembly = typeof(App).GetTypeInfo().Assembly;
// Get the custom attribute informations:
var titleAttribute = assembly.CustomAttributes.Where(ca => ca.AttributeType == typeof(AssemblyTitleAttribute)).FirstOrDefault();
// Now get the string value contained in the constructor:
return titleAttribute.ConstructorArguments[0].Value.ToString();
Hope this helps...
Upvotes: 1
Reputation: 18102
From your screenshot, it seems you want the assembly title. You can get the assembly title attribute at runtime by doing something like this:
// Get current assembly
var thisAssembly = this.GetType().Assembly;
// Get title attribute (on .NET 4)
var titleAttribute = thisAssembly
.GetCustomAttributes(typeof(AssemblyTitleAttribute), false)
.Cast<AssemblyTitleAttribute>()
.FirstOrDefault();
// Get title attribute (on .NET 4.5)
var titleAttribute = thisAssembly.GetCustomAttribute<AssemblyTitleAttribute>();
if (titleAttribute != null)
{
var title = titleAttribute.Title;
// Do something with title...
}
But remember, this is not the application name, this is the assembly title.
Upvotes: 2