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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Max

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

    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

  • Kevin Spencer

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

    It all depends on what the value of "file path" is. Perhaps you could give
    us an example of a "file path" that is not found?

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    Chicken Salad Surgery

    Accept the Unexpected.

    "Max" <mahesh.anjani@ gmail.comwrote in message
    news:1155221942 .579024.234910@ b28g2000cwb.goo glegroups.com.. .
    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
    >

    Comment

    • Reg Edit

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

      Sounds like you would need to use Server.MapPath - are you using it?



      Comment

      • Max

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

        followin is on of the file that gives error

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

        Access to the path
        "L:\Webhosting\ home.gujarat.go v.in\homeapps\i magefiles\image s.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.Unauthor izedAccessExcep tion: Access to the
        path "L:\Webhosting\ home.gujarat.go v.in\homeapps\i magefiles\image s.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}\ASPNE T 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="tr ue"/>, the identity will be the anonymous user
        (typically IUSR_MACHINENAM E) 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:


        [UnauthorizedAcc essException: Access to the path
        "L:\Webhosting\ home.gujarat.go v.in\homeapps\i magefiles\image s.jpg" is
        denied.]
        System.IO.__Err or.WinIOError(I nt32 errorCode, String str) +393
        System.IO.File. Delete(String path) +165
        CMSAPPS.mas_WMK D_entry.Save_AD D() in
        D:\dnSource\HOM EAPPS_mahesh\ma s_WMKD_entry.as px.vb:248
        CMSAPPS.mas_WMK D_entry.bttn_Sa ve_Click(Object sender, EventArgs e)
        in D:\dnSource\HOM EAPPS_mahesh\ma s_WMKD_entry.as px.vb:221
        System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108

        System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring
        eventArgument) +57
        System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
        sourceControl, String eventArgument) +18
        System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
        +33
        System.Web.UI.P age.ProcessRequ estMain() +1292

        Comment

        • Max

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


          Reg Edit wrote:
          Sounds like you would need to use Server.MapPath - are you using it?
          >
          http://support.microsoft.com/default...b;en-us;323245

          i have used server.mappath following is my code

          If file.Exists(Ser ver.MapPath("im agefiles/") & Session("upload img"))
          Then
          img = file.OpenRead(S erver.MapPath(" imagefiles/") &
          Session("upload img"))
          ReDim byteArr(img.Len gth)
          img.Read(byteAr r, 0,
          System.Convert. ToInt32(img.Len gth))
          img.Close()
          end if

          Comment

          • Ken Cox [Microsoft MVP]

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

            That's caused by the security settings that prevent subscribers of one web
            from poking around in the code of another web. Is it an ISP's server?

            "Max" <mahesh.anjani@ gmail.comwrote in message
            news:1155306104 .384207.320410@ i3g2000cwc.goog legroups.com...
            followin is on of the file that gives error
            >
            Server Error in '/' Application.
            --------------------------------------------------------------------------------
            >
            Access to the path
            "L:\Webhosting\ home.gujarat.go v.in\homeapps\i magefiles\image s.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.Unauthor izedAccessExcep tion: Access to the
            path "L:\Webhosting\ home.gujarat.go v.in\homeapps\i magefiles\image s.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}\ASPNE T 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="tr ue"/>, the identity will be the anonymous user
            (typically IUSR_MACHINENAM E) 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:
            >
            >
            [UnauthorizedAcc essException: Access to the path
            "L:\Webhosting\ home.gujarat.go v.in\homeapps\i magefiles\image s.jpg" is
            denied.]
            System.IO.__Err or.WinIOError(I nt32 errorCode, String str) +393
            System.IO.File. Delete(String path) +165
            CMSAPPS.mas_WMK D_entry.Save_AD D() in
            D:\dnSource\HOM EAPPS_mahesh\ma s_WMKD_entry.as px.vb:248
            CMSAPPS.mas_WMK D_entry.bttn_Sa ve_Click(Object sender, EventArgs e)
            in D:\dnSource\HOM EAPPS_mahesh\ma s_WMKD_entry.as px.vb:221
            System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +108
            >
            System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring
            eventArgument) +57
            System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler
            sourceControl, String eventArgument) +18
            System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
            +33
            System.Web.UI.P age.ProcessRequ estMain() +1292
            >

            Comment

            Working...