Kornél Regius
Kornél Regius

Reputation: 3049

Relative Path, usable in both Console Application and ASP.NET Webapplication

Is it possible to specify a path that is relative to the root of both a console and an asp.net webapplication? So

Example: Let's say I have a file called "log.txt". I have a logging component in a separate dll, that uses this log.txt under "logs" folder. I have two applications that use this component, one is a Console Application, the other one is an ASP.NET Web Application.

Is it possible to specify a relative path in the logging component, that will find the file at the following places?:

mywebapp/
-Web.Config
-bin/logging.dll
-other web files
-logs/log.txt

myconsoleapp/
-myconsoleapp.exe
-logging.dll
-some other dlls
-logs/log.txt

Upvotes: 2

Views: 6335

Answers (2)

Kornél Regius
Kornél Regius

Reputation: 3049

Use AppDomain.CurrentDomain.BaseDirectory

Reference:

Upvotes: 4

csteinmueller
csteinmueller

Reputation: 2487

I would recommend a little change:

Don't determine the path of your log within your logging component. Make it as a parameter. On the webàpplication you can use Server.MapPath (MSDN Server.MapPath Method) to map relative to absolute paths.

Upvotes: 1

Related Questions