Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

get application path in .NET

Options
  • 01-03-2006 10:56am
    #1
    Registered Users Posts: 4,073 ✭✭✭


    Ok, i've got a web application in .NET. It consists of a c# class library which encompases all the core functionality of the application, and an ASP.NET interface. The ASP.NET project uses the class library for it's functionality.

    The class library contains a log class for writing errors to a log. At the moment I have the path of the log file hard coded, but what I want it to do is create the log file in whatever directory the ASP.NET project is running in. So far I've tried System.AppDomain.CurrentDomain.BaseDirectory, Application.ExecutablePath, and Application.StartupPath but none give me the path I need.

    Does anyone know if it's possible to obtain the path of the ASP.NET app that references the class library, and if so, how?


Comments

  • Registered Users Posts: 2,758 ✭✭✭Peace


    Petr wrote this class...
    	public class App
    	{
    		public App()
    		{
    			//
    			// TODO: Add constructor logic here
    			//
    		}
    		public static string AppPath()
    		{
    			return System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
    			//return System.Windows.Forms.Application.StartupPath;
    
    		}
    
    
    	}
    

    I've commented out the Forms line as its not really applicable to your ASP stuff i believe.

    <edit>
    I forgot to mention that it works for any of the webservices we are using...
    </edit>


  • Registered Users Posts: 4,073 ✭✭✭muckwarrior


    Nice one. Just realised that I think I actually already had it working at one stage but didn't realise it because I forgot to publish the web project so it was giving me the debug path :o .


  • Moderators, Science, Health & Environment Moderators Posts: 8,950 Mod ✭✭✭✭mewso


    server.MapPath(request.ApplicationPath)


Advertisement