Finding ASP.NET temporary directory

Discussion in 'ASP .Net' started by Rik Hemsley, Feb 15, 2006.

  1. Rik Hemsley

    Rik Hemsley Guest

    Hi,

    I am looking for a way to discover the path to the ASP.NET temporary
    directory, which is called something like 'Temporary ASP.NET Files'.

    From within an ASP.NET application, I can get the path using
    IO.Path.GetTempPath(), but I need to do so from outside the application.
    I am currently using a web service for this, but this is a less than
    optimal solution: if the web service is unable to start, I don't get the
    full error message from IIS.

    Is there any way to ask ASP.NET what its temporary directory is?

    Thanks,
    Rik
     
    Rik Hemsley, Feb 15, 2006
    #1
    1. Advertising

  2. The temp directory is hard-coded.

    For .Net Framework 2.0 :
    bootdrive:\%windir%\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files

    For .Net Framework 1.1 :
    bootdrive:\%windir%\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files

    This is a real hack, but it will retrieve the Temp directory path programmatically :

    In global.asax :

    Sub Application_OnStart()
    Dim MyArray() As String = Split(AppDomain.CurrentDomain.DynamicDirectory, "\")
    Application("TEMP_DIR") = (MyArray(0).ToString() & "/" & MyArray(1).ToString() & "/" _
    & MyArray(2).ToString() & "/" & MyArray(3).ToString()) & "/" & MyArray(4).ToString() & "/" _
    & MyArray(5).ToString())
    End Sub

    The path to the machine's ASP.NET Temporary Files directory
    is now contained by Application("TEMP_DIR").

    You can probably parse MyArray(), to extract the temp dir,
    in a far simpler way, but I didn't have the time to do that for you right now.

    What you need to do is strip off MyArray(6), MyArray(7) and MyArray(8) from the
    string array created by Split(AppDomain.CurrentDomain.DynamicDirectory, "\").





    Juan T. Llibre, asp.net MVP
    aspnetfaq.com : http://www.aspnetfaq.com/
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en espaƱol : http://asp.net.do/foros/
    ===================================
    "Rik Hemsley" <> wrote in message news:...
    > Hi,
    >
    > I am looking for a way to discover the path to the ASP.NET temporary directory, which is called
    > something like 'Temporary ASP.NET Files'.
    >
    > From within an ASP.NET application, I can get the path using IO.Path.GetTempPath(), but I need to
    > do so from outside the application. I am currently using a web service for this, but this is a
    > less than optimal solution: if the web service is unable to start, I don't get the full error
    > message from IIS.
    >
    > Is there any way to ask ASP.NET what its temporary directory is?
    >
    > Thanks,
    > Rik
    >
     
    Juan T. Llibre, Feb 15, 2006
    #2
    1. Advertising

  3. Rik Hemsley

    Rik Hemsley Guest

    Juan T. Llibre wrote:
    > The temp directory is hard-coded.


    Sorry, I meant the 'other' temp directory, not the 'Temporary ASP.NET
    files' one. I'm not completely sure what this other directory is used
    for, but I know that I need to give write access to it to the user who
    the web application runs as, or I get 'permission denied' errors.

    When a web _service_ is running, IO.Path.GetTempPath() returns (for me):

    C:\DOCUME~1\RIK\ASPNET\LOCALS~1\Temp\

    RIK\ASPNET seems to be name-of-machine\ASPNET, rather than username\ASPNET.

    Looking at it again, I think it might be quite easy to work out what
    this path will be, without having to be a web service, so I'll give it a
    go and see if I can figure out a correct implementation.

    BTW for anyone wanting to get the 'Temporary ASP.NET files' directory
    from outside the web application, I do it like this:

    String.Format _
    ( _
    "{0}\Microsoft.NET\Framework\v{1}.{2}.{3}\Temporary ASP.NET Files", _
    Environment.GetEnvironmentVariable("windir"), _
    Environment.Version.Major, _
    Environment.Version.Minor, _
    Environment.Version.Build _
    )

    Cheers,
    Rik
     
    Rik Hemsley, Feb 16, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Juleke
    Replies:
    2
    Views:
    2,276
    Juleke
    Apr 12, 2004
  2. =?Utf-8?B?QmFzIEhlbmRyaWtz?=

    Directory and files names in temporary asp.net directory

    =?Utf-8?B?QmFzIEhlbmRyaWtz?=, Jan 28, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    854
    Juan T. Llibre
    Jan 31, 2005
  3. Replies:
    7
    Views:
    3,262
    James Kanze
    Feb 12, 2008
  4. Amelyan
    Replies:
    2
    Views:
    175
    Amelyan
    Apr 25, 2005
  5. David Thom
    Replies:
    0
    Views:
    140
    David Thom
    Jul 22, 2003
Loading...

Share This Page