views:

132

answers:

4

Hi,

I use a component (System.ComponentModel.Component) and I want to get the application path of my project in order to create a file within it.

Thx

Florian

A: 

Use AppDomain.CurrentDomain.BaseDirectory.

sashaeve
It does not work. When I dragged my compoment which have this method :public override void InitializeNewComponent(IDictionary defaultValues){ MessageBox.Show(AppDomain.CurrentDomain.BaseDirectory);}The messagebox appears with that : C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\IDE\
Florian
I suggest you test application with VS?
sashaeve
A: 

Does this work?

 New Uri(Assembly.GetCallingAssembly().CodeBase).AbsolutePath

("CallingAssembly" because you can put the method to retrieve the execution path into the service layer (assembly))

Robert
it doesn't work : here the result C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
Florian
A: 

Take a look at: http://stackoverflow.com/questions/723172/project-bin-folder-path-at-compile-time

With this technique you could "Build" (once) and after that use the generated file to get the project location at DesignTime. This would work workspace independent.

Robert
A: 

I think Robert is almost right.

This seems to work:

Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
Scott P