Results 1 to 3 of 3

Thread: [RESOLVED] Getting the application file path for a lcal debug project

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Posts
    230

    Resolved [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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Posts
    230

    Re: Getting the application file path for a lcal debug project

    Quote Originally Posted by jmcilhinney View Post
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width