system.IO.File.Exists doesn't working for file that is outside my virtual directory

Discussion in 'ASP .Net' started by Max, Aug 10, 2006.

  1. Max

    Max Guest

    hi

    i have file browser control to select any file and a button to upload
    file on my web page now when i select any file. now on click of upload
    button i have check that file exist or no

    if system.IO.File.Exist(file path) then
    ....
    end if
    now when ever i choose file system.IO.File.Exist(file path) return
    false, but if i select file from my virtual directory then only it
    return true.

    so how to select file from any folder on my PC and chech that it exist
    or not
     
    Max, Aug 10, 2006
    #1
    1. Advertising

  2. RE: system.IO.File.Exists doesn't working for file that is outside my

    Are you using an absolute path or a relative path to the file?


    "Max" wrote:

    > hi
    >
    > i have file browser control to select any file and a button to upload
    > file on my web page now when i select any file. now on click of upload
    > button i have check that file exist or no
    >
    > if system.IO.File.Exist(file path) then
    > ....
    > end if
    > now when ever i choose file system.IO.File.Exist(file path) return
    > false, but if i select file from my virtual directory then only it
    > return true.
    >
    > so how to select file from any folder on my PC and chech that it exist
    > or not
    >
    >
     
    =?Utf-8?B?Y2xpY2tvbg==?=, Aug 10, 2006
    #2
    1. Advertising

  3. Max

    tfsmag Guest

    It may have to do with the ASP.net user in IIS not having read
    permissions on the directories?

    Max wrote:
    > hi
    >
    > i have file browser control to select any file and a button to upload
    > file on my web page now when i select any file. now on click of upload
    > button i have check that file exist or no
    >
    > if system.IO.File.Exist(file path) then
    > ...
    > end if
    > now when ever i choose file system.IO.File.Exist(file path) return
    > false, but if i select file from my virtual directory then only it
    > return true.
    >
    > so how to select file from any folder on my PC and chech that it exist
    > or not
     
    tfsmag, Aug 10, 2006
    #3
  4. Max

    Max Guest

    Re: system.IO.File.Exists doesn't working for file that is outside my

    followin is the error i am getting

    Server Error in '/' Application.
    --------------------------------------------------------------------------------

    Access to the path
    "L:\Webhosting\home.gujarat.gov.in\homeapps\imagefiles\images.jpg" is
    denied.
    Description: An unhandled exception occurred during the execution of
    the current web request. Please review the stack trace for more
    information about the error and where it originated in the code.

    Exception Details: System.UnauthorizedAccessException: Access to the
    path "L:\Webhosting\home.gujarat.gov.in\homeapps\imagefiles\images.jpg"
    is denied.

    ASP.NET is not authorized to access the requested resource. Consider
    granting access rights to the resource to the ASP.NET request identity.
    ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS
    5 or Network Service on IIS 6) that is used if the application is not
    impersonating. If the application is impersonating via <identity
    impersonate="true"/>, the identity will be the anonymous user
    (typically IUSR_MACHINENAME) or the authenticated request user.

    To grant ASP.NET write access to a file, right-click the file in
    Explorer, choose "Properties" and select the Security tab. Click "Add"
    to add the appropriate user or group. Highlight the ASP.NET account,
    and check the boxes for the desired access.

    Source Error:

    An unhandled exception was generated during the execution of the
    current web request. Information regarding the origin and location of
    the exception can be identified using the exception stack trace below.


    Stack Trace:


    [UnauthorizedAccessException: Access to the path
    "L:\Webhosting\home.gujarat.gov.in\homeapps\imagefiles\images.jpg" is
    denied.]
    System.IO.__Error.WinIOError(Int32 errorCode, String str) +393
    System.IO.File.Delete(String path) +165
    CMSAPPS.mas_WMKD_entry.Save_ADD() in
    D:\dnSource\HOMEAPPS_mahesh\mas_WMKD_entry.aspx.vb:248
    CMSAPPS.mas_WMKD_entry.bttn_Save_Click(Object sender, EventArgs e)
    in D:\dnSource\HOMEAPPS_mahesh\mas_WMKD_entry.aspx.vb:221
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
    eventArgument) +57
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    sourceControl, String eventArgument) +18
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    +33
    System.Web.UI.Page.ProcessRequestMain() +1292
     
    Max, Aug 11, 2006
    #4
  5. Re: system.IO.File.Exists doesn't working for file that is outside my

    What do you not understand about the exception's explanation?

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    Chicken Salad Surgery

    Orange you bland I stopped splaying bananas?


    "Max" <> wrote in message
    news:...
    > followin is the error i am getting
    >
    > Server Error in '/' Application.
    > --------------------------------------------------------------------------------
    >
    > Access to the path
    > "L:\Webhosting\home.gujarat.gov.in\homeapps\imagefiles\images.jpg" is
    > denied.
    > Description: An unhandled exception occurred during the execution of
    > the current web request. Please review the stack trace for more
    > information about the error and where it originated in the code.
    >
    > Exception Details: System.UnauthorizedAccessException: Access to the
    > path "L:\Webhosting\home.gujarat.gov.in\homeapps\imagefiles\images.jpg"
    > is denied.
    >
    > ASP.NET is not authorized to access the requested resource. Consider
    > granting access rights to the resource to the ASP.NET request identity.
    > ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS
    > 5 or Network Service on IIS 6) that is used if the application is not
    > impersonating. If the application is impersonating via <identity
    > impersonate="true"/>, the identity will be the anonymous user
    > (typically IUSR_MACHINENAME) or the authenticated request user.
    >
    > To grant ASP.NET write access to a file, right-click the file in
    > Explorer, choose "Properties" and select the Security tab. Click "Add"
    > to add the appropriate user or group. Highlight the ASP.NET account,
    > and check the boxes for the desired access.
    >
    > Source Error:
    >
    > An unhandled exception was generated during the execution of the
    > current web request. Information regarding the origin and location of
    > the exception can be identified using the exception stack trace below.
    >
    >
    > Stack Trace:
    >
    >
    > [UnauthorizedAccessException: Access to the path
    > "L:\Webhosting\home.gujarat.gov.in\homeapps\imagefiles\images.jpg" is
    > denied.]
    > System.IO.__Error.WinIOError(Int32 errorCode, String str) +393
    > System.IO.File.Delete(String path) +165
    > CMSAPPS.mas_WMKD_entry.Save_ADD() in
    > D:\dnSource\HOMEAPPS_mahesh\mas_WMKD_entry.aspx.vb:248
    > CMSAPPS.mas_WMKD_entry.bttn_Save_Click(Object sender, EventArgs e)
    > in D:\dnSource\HOMEAPPS_mahesh\mas_WMKD_entry.aspx.vb:221
    > System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
    >
    > System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
    > eventArgument) +57
    > System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    > sourceControl, String eventArgument) +18
    > System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    > +33
    > System.Web.UI.Page.ProcessRequestMain() +1292
    >
     
    Kevin Spencer, Aug 11, 2006
    #5
    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. Pgar
    Replies:
    1
    Views:
    4,931
    =?Utf-8?B?U2FudGhhbmEgR29wYWxhbg==?=
    Nov 15, 2004
  2. Shafter
    Replies:
    1
    Views:
    3,356
    bruce barker
    Jan 7, 2005
  3. Totan
    Replies:
    0
    Views:
    1,032
    Totan
    Apr 17, 2006
  4. OK
    Replies:
    9
    Views:
    447
    Eliyahu Goldin
    Mar 30, 2008
  5. Ulf Meinhardt
    Replies:
    8
    Views:
    6,224
Loading...

Share This Page