2

I have a project, built with Visual Web Developer 2008. I want to be able to extract (with C#), the current folder the project is in now. Until now I had to hard code the true path.

This project is hosted on my computer.

For example, the path I would like to generate:

C:\Users\Guy\Desktop\Project 

Thanks! Guy

1
  • 1
    Do you mean the location of the project 'I.e. the .cs' file? or the build output? Commented May 23, 2012 at 11:28

5 Answers 5

11

Directory Of Base Assembly Resolver:

AppDomain.CurrentDomain.BaseDirectory; 
Sign up to request clarification or add additional context in comments.

Comments

2

The safest way:

string temp = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase); 

Comments

2

If you are only reading, then

Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase); 

works. But if you want to write to, then you'd have to go with:

AppDomain.CurrentDomain.BaseDirectory; 

Or you will get an

{"URI formats are not supported."} 

exception because your path is

file:\\C:\\Projects\ 

instead of

C:\\Projects 

Comments

1

To map a page (or Virtual Directory) to the filesystem location (at runtime) you can user Server.MapPath("/")

Comments

1

Use:

Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.