CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    971

    how do you find out what the name of your app is

    What is the function that let you know what the name of your App (.exe) is and from where it is being run from ?


    cheers

  2. #2
    Join Date
    May 2003
    Location
    Germany
    Posts
    936

    Re: how do you find out what the name of your app is

    If you have defined the application name in your AssemblyInfo.cs you can read the application name by using the following code.
    Code:
            private string AssemblyTitle
            {
                get
                {
                    // Get all Title attributes on this assembly
                    object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                    // If there is at least one Title attribute
                    if (attributes.Length > 0)
                    {
                        // Select the first one
                        AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
                        // If it is not an empty string, return it
                        if (titleAttribute.Title != "")
                            return titleAttribute.Title;
                    }
                    // If there was no Title attribute, or if the Title attribute was the empty string, return the .exe name
                    return Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
                }
            }
    And this should give you the right location.
    Code:
    string location = Assembly.GetExecutingAssembly().Location;
    Useful or not? Rate my posting. Thanks.

  3. #3
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    1,080

    Re: how do you find out what the name of your app is

    Assuming that you're running a Windows Forms app use Application.ExecutablePath and Application.StartupPath.
    Tutorials: Home & Learn | Start VB.NET | Learn VB.NET | C# Station | GotDotNet | Games in VB.NET 101 Samples: 2002 | 2003 | 2005 | More .NET 2.0 (VB.NET, C#) Articles: VB.NET | C# | ASP.NET | MoreFree Components: WFC | XPCC | ElementsEx | VBPP | Mentalis | ADO.NET/MySQL | VisualStyles | Charting (NPlot, ZedGraph) | iTextSharp (PDF) | SDF (CF) ● Free Literature: VB 2005 (eBook) | VB6 to VB.NET (eBook) | MSDN Magazine (CHM format) ● Bookmarks: MSDN | WinForms .NET | ASP.NET | WinForms FAQ | WebForms FAQ | GotDotNet | Code Project | DevBuzz (CF) ● Code Converter: C#/VB.NET | VB.NET/C# | VS 2005 add-in

  4. #4
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    971

    Re: how do you find out what the name of your app is

    Yea thanks
    but what do i have to include on top of the file
    Error 1 The name 'Assembly' does not exist in the current context ?


    Cheers

  5. #5
    Join Date
    Aug 2007
    Location
    Minneapolis
    Posts
    155

    Re: how do you find out what the name of your app is

    Include
    Code:
    using System.Reflection;

  6. #6
    Join Date
    May 1999
    Location
    G day Mayt Land
    Posts
    971

    Thumbs up Re: how do you find out what the name of your app is

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured