Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 576381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:02:27+00:00 2026-05-13T14:02:27+00:00

How do I get the application’s directory from my WPF application, at design time?

  • 0

How do I get the application’s directory from my WPF application, at design time? I need to access a resource in my application’s current directory at design time, while my XAML is being displayed in the designer. I’m not able to use the solution specified in this question as at design time both System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) and System.Reflection.Assembly.GetExecutingAssembly().Location point to the IDE’s location (Visual Studio… Common7 or something).

Upon request to further clarify my goals: I want to access a database table at design time and display a graphic of that data. The design is done in Visual Studio 2008, so what I need is a very specific solution to a very specific problem, and that is getting the assembly directory for my app.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:02:28+00:00Added an answer on May 13, 2026 at 2:02 pm

    From your description it sounds like your code is actually running inside the WPF Designer within Visual Studio, for example it is part of a custom control library that is being used for design.

    In this case, Assembly.GetEntryAssembly() returns null, but the following code gets the path to the application directory:

      string applicationDirectory = (
        from assembly in AppDomain.CurrentDomain.GetAssemblies()
        where assembly.CodeBase.EndsWith(".exe")
        select System.IO.Path.GetDirectoryName(assembly.CodeBase.Replace("file:///", ""))
        ).FirstOrDefault();
    

    The following steps can be used to demonstrate this works inside VS.NET 2008’s WPF Designer tool:

    1. Place this code inside a “WPF Custom Control Library” or “Class Library” project
    2. Add whatever code is necessary to read the database and return the data for display (in my case I just returned the application directory itself as a string)
    3. Reference the library project from the project you are designing
    4. Use the custom controls or classes from a XAML file to populate your DataContext or otherwise supply data to your UI (in my case I bound DataContext using x:Static)
    5. Edit that XAML file with the “Windows Presentation Foundation Designer”, which can be done by just double-clicking unless you have changed your default editor, in which case use “Open With…”

    When you follow these steps, the object you are looking at will be populated with data from your database the same way both at run time and design time.

    There are other scenarios in which this same technique works just as well, and there are other solutions available depending on your needs. Please let us know if your needs are different those I assumed above. For example, if you are writing a VS.NET add-in, you are in a completely different ball game.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 375k
  • Answers 375k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would suggest loading the results of the XML Parsing… May 14, 2026 at 8:11 pm
  • Editorial Team
    Editorial Team added an answer You should see Coding for (Battery) Life Google IO presentation,… May 14, 2026 at 8:11 pm
  • Editorial Team
    Editorial Team added an answer You can use Lua's native 'execute' command. Example: os.execute("c:\\temp\\program.exe") Sources:… May 14, 2026 at 8:11 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.