[RESOLVED] Getting the application file path for a lcal debug project
I want to get the file path for the current file in the project file. I've tried various approaches but they all point to the folder in the IIS that the site is executing in. The reason I need this is because i have an images folder in the project which needs to be accessible with a relative path to the project.
Thanks
Re: Getting the application file path for a lcal debug project
The project is irrelevant. The project doesn't exist at run time. When you build the project the source files are compiled and transformed and the compiled output is placed in a folder. That folder is your root and that's what matters. Whether you are running in the debugger or deployed to a web server, that root folder is what matters.
I'm guessing that you're using Application.StartupPath or the like, right? That's not for web apps. Web apps are actually libraries loaded by the web server. That's why it's giving you IIS paths.
In web apps you can use "~" to represent your root folder and then go from there. If you have an Images folder under the root folder then the relative path is "~\Images". In an ASP.NET Web Forms page, you can use Server.MapPath to get the absolute path that corresponds to that virtual path.
Re: Getting the application file path for a lcal debug project
Quote:
Originally Posted by
jmcilhinney
The project is irrelevant. The project doesn't exist at run time. When you build the project the source files are compiled and transformed and the compiled output is placed in a folder. That folder is your root and that's what matters. Whether you are running in the debugger or deployed to a web server, that root folder is what matters.
I'm guessing that you're using Application.StartupPath or the like, right? That's not for web apps. Web apps are actually libraries loaded by the web server. That's why it's giving you IIS paths.
In web apps you can use "~" to represent your root folder and then go from there. If you have an Images folder under the root folder then the relative path is "~\Images". In an ASP.NET Web Forms page, you can use Server.MapPath to get the absolute path that corresponds to that virtual path.
Thanks, I got around this issue by storing the images in the App_Data folder and then getting the path that way.