Exceptional Error

Discussion in 'ASP .Net' started by mohit, Dec 20, 2005.

  1. mohit

    mohit Guest

    Hi,
    I am creating a web application in Web Matrix on the .NET
    framework.
    I have two directories :AddUser and FormAuth in a Directory P.

    AddUser contains a file AddUser.aspx
    FormAuth contains : Default.aspx , Users.xml , Login.aspx

    I have the following code :

    DataSet ds = new DataSet();

    String userFile = "../Users.xml";

    FileStream fs = new FileStream(Server.MapPath(userFile),
    FileMode.Open,FileAccess.Read);
    StreamReader reader = new StreamReader(fs);
    ds.ReadXml(reader);
    fs.Close();


    When I run it it gives the following exception :

    [HttpException (0x80004005): Cannot use a leading .. to exit above the
    top directory.]
    System.Web.Util.UrlPath.Reduce(String path) +581
    System.Web.Util.UrlPath.Combine(String basepath, String relative)
    +251
    System.Web.HttpRequest.MapPath(String virtualPath, String
    baseVirtualDir, Boolean allowCrossAppMapping) +192
    System.Web.HttpServerUtility.MapPath(String path) +61
    ASP.AddUser_aspx.Button1_Click(Object sender, EventArgs e) in F:\DC
    Downlaods(complete)\mohitag\MyProject\AddUser\AddUser.aspx:28
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83

    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() +1263

    IF YOU HAVE SOME IDEA PLEASE TELL ME AS SOON AS POSSIBLE.

    Thank you very much
     
    mohit, Dec 20, 2005
    #1
    1. Advertising

  2. Your web server doesn't allow parent paths. You either have to use a
    root-relative path, and absolute path, or configure your web server to allow
    parent paths.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    You can lead a fish to a bicycle,
    but it takes a very long time,
    and the bicycle has to *want* to change.

    "mohit" <> wrote in message
    news:...
    > Hi,
    > I am creating a web application in Web Matrix on the .NET
    > framework.
    > I have two directories :AddUser and FormAuth in a Directory P.
    >
    > AddUser contains a file AddUser.aspx
    > FormAuth contains : Default.aspx , Users.xml , Login.aspx
    >
    > I have the following code :
    >
    > DataSet ds = new DataSet();
    >
    > String userFile = "../Users.xml";
    >
    > FileStream fs = new FileStream(Server.MapPath(userFile),
    > FileMode.Open,FileAccess.Read);
    > StreamReader reader = new StreamReader(fs);
    > ds.ReadXml(reader);
    > fs.Close();
    >
    >
    > When I run it it gives the following exception :
    >
    > [HttpException (0x80004005): Cannot use a leading .. to exit above the
    > top directory.]
    > System.Web.Util.UrlPath.Reduce(String path) +581
    > System.Web.Util.UrlPath.Combine(String basepath, String relative)
    > +251
    > System.Web.HttpRequest.MapPath(String virtualPath, String
    > baseVirtualDir, Boolean allowCrossAppMapping) +192
    > System.Web.HttpServerUtility.MapPath(String path) +61
    > ASP.AddUser_aspx.Button1_Click(Object sender, EventArgs e) in F:\DC
    > Downlaods(complete)\mohitag\MyProject\AddUser\AddUser.aspx:28
    > System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83
    >
    > 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() +1263
    >
    > IF YOU HAVE SOME IDEA PLEASE TELL ME AS SOON AS POSSIBLE.
    >
    > Thank you very much
    >
     
    Kevin Spencer, Dec 20, 2005
    #2
    1. Advertising

  3. mohit

    mohit Guest

    Neither the root relative path nor the absolute path are working.
    could you please tell me how to configure windows to allow parent
    paths.
    Thanks

    Kevin Spencer wrote:
    > Your web server doesn't allow parent paths. You either have to use a
    > root-relative path, and absolute path, or configure your web server to allow
    > parent paths.
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Microsoft MVP
    > .Net Developer
    > You can lead a fish to a bicycle,
    > but it takes a very long time,
    > and the bicycle has to *want* to change.
    >
    > "mohit" <> wrote in message
    > news:...
    > > Hi,
    > > I am creating a web application in Web Matrix on the .NET
    > > framework.
    > > I have two directories :AddUser and FormAuth in a Directory P.
    > >
    > > AddUser contains a file AddUser.aspx
    > > FormAuth contains : Default.aspx , Users.xml , Login.aspx
    > >
    > > I have the following code :
    > >
    > > DataSet ds = new DataSet();
    > >
    > > String userFile = "../Users.xml";
    > >
    > > FileStream fs = new FileStream(Server.MapPath(userFile),
    > > FileMode.Open,FileAccess.Read);
    > > StreamReader reader = new StreamReader(fs);
    > > ds.ReadXml(reader);
    > > fs.Close();
    > >
    > >
    > > When I run it it gives the following exception :
    > >
    > > [HttpException (0x80004005): Cannot use a leading .. to exit above the
    > > top directory.]
    > > System.Web.Util.UrlPath.Reduce(String path) +581
    > > System.Web.Util.UrlPath.Combine(String basepath, String relative)
    > > +251
    > > System.Web.HttpRequest.MapPath(String virtualPath, String
    > > baseVirtualDir, Boolean allowCrossAppMapping) +192
    > > System.Web.HttpServerUtility.MapPath(String path) +61
    > > ASP.AddUser_aspx.Button1_Click(Object sender, EventArgs e) in F:\DC
    > > Downlaods(complete)\mohitag\MyProject\AddUser\AddUser.aspx:28
    > > System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83
    > >
    > > 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() +1263
    > >
    > > IF YOU HAVE SOME IDEA PLEASE TELL ME AS SOON AS POSSIBLE.
    > >
    > > Thank you very much
    > >
     
    mohit, Dec 20, 2005
    #3
  4. This is done through the IIS Admin tool, not Windows. Web Site Properties -
    Home Directory Tab - Configure Button - Options Tab.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    You can lead a fish to a bicycle,
    but it takes a very long time,
    and the bicycle has to *want* to change.

    "mohit" <> wrote in message
    news:...
    > Neither the root relative path nor the absolute path are working.
    > could you please tell me how to configure windows to allow parent
    > paths.
    > Thanks
    >
    > Kevin Spencer wrote:
    >> Your web server doesn't allow parent paths. You either have to use a
    >> root-relative path, and absolute path, or configure your web server to
    >> allow
    >> parent paths.
    >>
    >> --
    >> HTH,
    >>
    >> Kevin Spencer
    >> Microsoft MVP
    >> .Net Developer
    >> You can lead a fish to a bicycle,
    >> but it takes a very long time,
    >> and the bicycle has to *want* to change.
    >>
    >> "mohit" <> wrote in message
    >> news:...
    >> > Hi,
    >> > I am creating a web application in Web Matrix on the .NET
    >> > framework.
    >> > I have two directories :AddUser and FormAuth in a Directory P.
    >> >
    >> > AddUser contains a file AddUser.aspx
    >> > FormAuth contains : Default.aspx , Users.xml , Login.aspx
    >> >
    >> > I have the following code :
    >> >
    >> > DataSet ds = new DataSet();
    >> >
    >> > String userFile = "../Users.xml";
    >> >
    >> > FileStream fs = new FileStream(Server.MapPath(userFile),
    >> > FileMode.Open,FileAccess.Read);
    >> > StreamReader reader = new StreamReader(fs);
    >> > ds.ReadXml(reader);
    >> > fs.Close();
    >> >
    >> >
    >> > When I run it it gives the following exception :
    >> >
    >> > [HttpException (0x80004005): Cannot use a leading .. to exit above the
    >> > top directory.]
    >> > System.Web.Util.UrlPath.Reduce(String path) +581
    >> > System.Web.Util.UrlPath.Combine(String basepath, String relative)
    >> > +251
    >> > System.Web.HttpRequest.MapPath(String virtualPath, String
    >> > baseVirtualDir, Boolean allowCrossAppMapping) +192
    >> > System.Web.HttpServerUtility.MapPath(String path) +61
    >> > ASP.AddUser_aspx.Button1_Click(Object sender, EventArgs e) in F:\DC
    >> > Downlaods(complete)\mohitag\MyProject\AddUser\AddUser.aspx:28
    >> > System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83
    >> >
    >> > 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() +1263
    >> >
    >> > IF YOU HAVE SOME IDEA PLEASE TELL ME AS SOON AS POSSIBLE.
    >> >
    >> > Thank you very much
    >> >

    >
     
    Kevin Spencer, Dec 20, 2005
    #4
  5. mohit

    mohit Guest

    I have tried it. I am using IIS in Windows XP.
    The errors are as following :

    if the code is : String userFile = "../Users.xml";

    FileStream fs = new FileStream(Server.MapPath(userFile),
    FileMode.Open,FileAccess.Read);


    Error is :Exception Details: System.Web.HttpException: Cannot use a
    leading .. to exit above the top directory.

    If the code is : String userFile = "FormsAuth/Users.xml"; or
    "/FormsAuth/Users.xml"

    FileStream fs = new FileStream(Server.MapPath(userFile),
    FileMode.Open,FileAccess.Read);


    Error :Exception Details: System.IO.DirectoryNotFoundException: Could
    not find a part of the path "F:\DC
    Downlaods(complete)\mohitag\MyProject\AddUser\FormsAuth\Users.xml".

    If the code is: String userFile = "F:\DC
    Downlaods(complete)\mohitag\MyProject\FormsAuth\Users.xml";

    FileStream fs = new FileStream(Server.MapPath(userFile),
    FileMode.Open,FileAccess.Read);


    Error : Compiler Error Message: CS1009: Unrecognized escape sequence

    Thank you very much.

    Kevin Spencer wrote:
    > This is done through the IIS Admin tool, not Windows. Web Site Properties -
    > Home Directory Tab - Configure Button - Options Tab.
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Microsoft MVP
    > .Net Developer
    > You can lead a fish to a bicycle,
    > but it takes a very long time,
    > and the bicycle has to *want* to change.
    >
    > "mohit" <> wrote in message
    > news:...
    > > Neither the root relative path nor the absolute path are working.
    > > could you please tell me how to configure windows to allow parent
    > > paths.
    > > Thanks
    > >
    > > Kevin Spencer wrote:
    > >> Your web server doesn't allow parent paths. You either have to use a
    > >> root-relative path, and absolute path, or configure your web server to
    > >> allow
    > >> parent paths.
    > >>
    > >> --
    > >> HTH,
    > >>
    > >> Kevin Spencer
    > >> Microsoft MVP
    > >> .Net Developer
    > >> You can lead a fish to a bicycle,
    > >> but it takes a very long time,
    > >> and the bicycle has to *want* to change.
    > >>
    > >> "mohit" <> wrote in message
    > >> news:...
    > >> > Hi,
    > >> > I am creating a web application in Web Matrix on the .NET
    > >> > framework.
    > >> > I have two directories :AddUser and FormAuth in a Directory P.
    > >> >
    > >> > AddUser contains a file AddUser.aspx
    > >> > FormAuth contains : Default.aspx , Users.xml , Login.aspx
    > >> >
    > >> > I have the following code :
    > >> >
    > >> > DataSet ds = new DataSet();
    > >> >
    > >> > String userFile = "../Users.xml";
    > >> >
    > >> > FileStream fs = new FileStream(Server.MapPath(userFile),
    > >> > FileMode.Open,FileAccess.Read);
    > >> > StreamReader reader = new StreamReader(fs);
    > >> > ds.ReadXml(reader);
    > >> > fs.Close();
    > >> >
    > >> >
    > >> > When I run it it gives the following exception :
    > >> >
    > >> > [HttpException (0x80004005): Cannot use a leading .. to exit above the
    > >> > top directory.]
    > >> > System.Web.Util.UrlPath.Reduce(String path) +581
    > >> > System.Web.Util.UrlPath.Combine(String basepath, String relative)
    > >> > +251
    > >> > System.Web.HttpRequest.MapPath(String virtualPath, String
    > >> > baseVirtualDir, Boolean allowCrossAppMapping) +192
    > >> > System.Web.HttpServerUtility.MapPath(String path) +61
    > >> > ASP.AddUser_aspx.Button1_Click(Object sender, EventArgs e) in F:\DC
    > >> > Downlaods(complete)\mohitag\MyProject\AddUser\AddUser.aspx:28
    > >> > System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83
    > >> >
    > >> > 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() +1263
    > >> >
    > >> > IF YOU HAVE SOME IDEA PLEASE TELL ME AS SOON AS POSSIBLE.
    > >> >
    > >> > Thank you very much
    > >> >

    > >
     
    mohit, Dec 20, 2005
    #5
  6. You have 4 distinctly different problems here:

    (1)
    > String userFile = "../Users.xml";
    >
    > FileStream fs = new FileStream(Server.MapPath(userFile),
    > FileMode.Open,FileAccess.Read);


    > Error is :Exception Details: System.Web.HttpException: Cannot use a
    > leading .. to exit above the top directory.


    This would indicate that the current HttpContext of the Page is in the root
    (top) directory of the app. The ".." indicates a directory above that one,
    which is below the top directory, and therefore outside the ASP.Net app.
    This is a security feature of ASP.Net. You can use a root-relative path
    instead, such as: "/Users.xml"

    (2)
    > String userFile = "FormsAuth/Users.xml"; or
    > "/FormsAuth/Users.xml"
    >
    > FileStream fs = new FileStream(Server.MapPath(userFile),


    > Error :Exception Details: System.IO.DirectoryNotFoundException: Could
    > not find a part of the path "F:\DC
    > Downlaods(complete)\mohitag\MyProject\AddUser\FormsAuth\Users.xml".


    The path that is indicated in the error message doesn't exist.

    (3)
    String userFile = "F:\DC
    > Downlaods(complete)\mohitag\MyProject\FormsAuth\Users.xml";
    >
    > FileStream fs = new FileStream(Server.MapPath(userFile),
    > FileMode.Open,FileAccess.Read);


    > Error : Compiler Error Message: CS1009: Unrecognized escape sequence


    The "\" character in C# is an escape sequence. You have to escape it with
    another "\" character (as in "\\" to represent a "\" character in a string.

    (4)
    You're programming by guesswork. This is the biggest problem of all. It will
    cost you beaucoups time. Do you have the Microsoft .Net SDK? You can
    download it for free from:

    http://msdn.microsoft.com/netframework/downloads/updates/default.aspx

    This page has links to the Framework SDK for both 1.1 and 2.0 framework
    versions.

    You'll save yourself a lot of time by using it. Ever since the first version
    of the Framework was released, I've spent about an hour a day on average
    reading in it.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    You can lead a fish to a bicycle,
    but it takes a very long time,
    and the bicycle has to *want* to change.


    "mohit" <> wrote in message
    news:...
    >I have tried it. I am using IIS in Windows XP.
    > The errors are as following :
    >
    > if the code is : String userFile = "../Users.xml";
    >
    > FileStream fs = new FileStream(Server.MapPath(userFile),
    > FileMode.Open,FileAccess.Read);
    >
    >
    > Error is :Exception Details: System.Web.HttpException: Cannot use a
    > leading .. to exit above the top directory.
    >
    > If the code is : String userFile = "FormsAuth/Users.xml"; or
    > "/FormsAuth/Users.xml"
    >
    > FileStream fs = new FileStream(Server.MapPath(userFile),
    >
    >
    > Error :Exception Details: System.IO.DirectoryNotFoundException: Could
    > not find a part of the path "F:\DC
    > Downlaods(complete)\mohitag\MyProject\AddUser\FormsAuth\Users.xml".
    >
    > If the code is: String userFile = "F:\DC
    > Downlaods(complete)\mohitag\MyProject\FormsAuth\Users.xml";
    >
    > FileStream fs = new FileStream(Server.MapPath(userFile),
    > FileMode.Open,FileAccess.Read);
    >
    >
    > Error : Compiler Error Message: CS1009: Unrecognized escape sequence
    >
    > Thank you very much.
    >
    > Kevin Spencer wrote:
    >> This is done through the IIS Admin tool, not Windows. Web Site
    >> Properties -
    >> Home Directory Tab - Configure Button - Options Tab.
    >>
    >> --
    >> HTH,
    >>
    >> Kevin Spencer
    >> Microsoft MVP
    >> .Net Developer
    >> You can lead a fish to a bicycle,
    >> but it takes a very long time,
    >> and the bicycle has to *want* to change.
    >>
    >> "mohit" <> wrote in message
    >> news:...
    >> > Neither the root relative path nor the absolute path are working.
    >> > could you please tell me how to configure windows to allow parent
    >> > paths.
    >> > Thanks
    >> >
    >> > Kevin Spencer wrote:
    >> >> Your web server doesn't allow parent paths. You either have to use a
    >> >> root-relative path, and absolute path, or configure your web server to
    >> >> allow
    >> >> parent paths.
    >> >>
    >> >> --
    >> >> HTH,
    >> >>
    >> >> Kevin Spencer
    >> >> Microsoft MVP
    >> >> .Net Developer
    >> >> You can lead a fish to a bicycle,
    >> >> but it takes a very long time,
    >> >> and the bicycle has to *want* to change.
    >> >>
    >> >> "mohit" <> wrote in message
    >> >> news:...
    >> >> > Hi,
    >> >> > I am creating a web application in Web Matrix on the .NET
    >> >> > framework.
    >> >> > I have two directories :AddUser and FormAuth in a Directory P.
    >> >> >
    >> >> > AddUser contains a file AddUser.aspx
    >> >> > FormAuth contains : Default.aspx , Users.xml , Login.aspx
    >> >> >
    >> >> > I have the following code :
    >> >> >
    >> >> > DataSet ds = new DataSet();
    >> >> >
    >> >> > String userFile = "../Users.xml";
    >> >> >
    >> >> > FileStream fs = new FileStream(Server.MapPath(userFile),
    >> >> > FileMode.Open,FileAccess.Read);
    >> >> > StreamReader reader = new StreamReader(fs);
    >> >> > ds.ReadXml(reader);
    >> >> > fs.Close();
    >> >> >
    >> >> >
    >> >> > When I run it it gives the following exception :
    >> >> >
    >> >> > [HttpException (0x80004005): Cannot use a leading .. to exit above
    >> >> > the
    >> >> > top directory.]
    >> >> > System.Web.Util.UrlPath.Reduce(String path) +581
    >> >> > System.Web.Util.UrlPath.Combine(String basepath, String relative)
    >> >> > +251
    >> >> > System.Web.HttpRequest.MapPath(String virtualPath, String
    >> >> > baseVirtualDir, Boolean allowCrossAppMapping) +192
    >> >> > System.Web.HttpServerUtility.MapPath(String path) +61
    >> >> > ASP.AddUser_aspx.Button1_Click(Object sender, EventArgs e) in
    >> >> > F:\DC
    >> >> > Downlaods(complete)\mohitag\MyProject\AddUser\AddUser.aspx:28
    >> >> > System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83
    >> >> >
    >> >> > 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() +1263
    >> >> >
    >> >> > IF YOU HAVE SOME IDEA PLEASE TELL ME AS SOON AS POSSIBLE.
    >> >> >
    >> >> > Thank you very much
    >> >> >
    >> >

    >
     
    Kevin Spencer, Dec 21, 2005
    #6
  7. mohit

    mohit Guest

    Following your instructions when I give the absolute path it says that
    the path is invalid and asks for virtual path.
    When I give the virtual path it says that the path does not exist.I
    have even configured my web server for the parent path.
    This all is becoming very messy to me.I am unable to understand where
    the major mistake is.

    Please guide me.

    Thank you.

    Kevin Spencer wrote:
    > You have 4 distinctly different problems here:
    >
    > (1)
    > > String userFile = "../Users.xml";
    > >
    > > FileStream fs = new FileStream(Server.MapPath(userFile),
    > > FileMode.Open,FileAccess.Read);

    >
    > > Error is :Exception Details: System.Web.HttpException: Cannot use a
    > > leading .. to exit above the top directory.

    >
    > This would indicate that the current HttpContext of the Page is in the root
    > (top) directory of the app. The ".." indicates a directory above that one,
    > which is below the top directory, and therefore outside the ASP.Net app.
    > This is a security feature of ASP.Net. You can use a root-relative path
    > instead, such as: "/Users.xml"
    >
    > (2)
    > > String userFile = "FormsAuth/Users.xml"; or
    > > "/FormsAuth/Users.xml"
    > >
    > > FileStream fs = new FileStream(Server.MapPath(userFile),

    >
    > > Error :Exception Details: System.IO.DirectoryNotFoundException: Could
    > > not find a part of the path "F:\DC
    > > Downlaods(complete)\mohitag\MyProject\AddUser\FormsAuth\Users.xml".

    >
    > The path that is indicated in the error message doesn't exist.
    >
    > (3)
    > String userFile = "F:\DC
    > > Downlaods(complete)\mohitag\MyProject\FormsAuth\Users.xml";
    > >
    > > FileStream fs = new FileStream(Server.MapPath(userFile),
    > > FileMode.Open,FileAccess.Read);

    >
    > > Error : Compiler Error Message: CS1009: Unrecognized escape sequence

    >
    > The "\" character in C# is an escape sequence. You have to escape it with
    > another "\" character (as in "\\" to represent a "\" character in a string.
    >
    > (4)
    > You're programming by guesswork. This is the biggest problem of all. It will
    > cost you beaucoups time. Do you have the Microsoft .Net SDK? You can
    > download it for free from:
    >
    > http://msdn.microsoft.com/netframework/downloads/updates/default.aspx
    >
    > This page has links to the Framework SDK for both 1.1 and 2.0 framework
    > versions.
    >
    > You'll save yourself a lot of time by using it. Ever since the first version
    > of the Framework was released, I've spent about an hour a day on average
    > reading in it.
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Microsoft MVP
    > .Net Developer
    > You can lead a fish to a bicycle,
    > but it takes a very long time,
    > and the bicycle has to *want* to change.
    >
    >
    > "mohit" <> wrote in message
    > news:...
    > >I have tried it. I am using IIS in Windows XP.
    > > The errors are as following :
    > >
    > > if the code is : String userFile = "../Users.xml";
    > >
    > > FileStream fs = new FileStream(Server.MapPath(userFile),
    > > FileMode.Open,FileAccess.Read);
    > >
    > >
    > > Error is :Exception Details: System.Web.HttpException: Cannot use a
    > > leading .. to exit above the top directory.
    > >
    > > If the code is : String userFile = "FormsAuth/Users.xml"; or
    > > "/FormsAuth/Users.xml"
    > >
    > > FileStream fs = new FileStream(Server.MapPath(userFile),
    > >
    > >
    > > Error :Exception Details: System.IO.DirectoryNotFoundException: Could
    > > not find a part of the path "F:\DC
    > > Downlaods(complete)\mohitag\MyProject\AddUser\FormsAuth\Users.xml".
    > >
    > > If the code is: String userFile = "F:\DC
    > > Downlaods(complete)\mohitag\MyProject\FormsAuth\Users.xml";
    > >
    > > FileStream fs = new FileStream(Server.MapPath(userFile),
    > > FileMode.Open,FileAccess.Read);
    > >
    > >
    > > Error : Compiler Error Message: CS1009: Unrecognized escape sequence
    > >
    > > Thank you very much.
    > >
    > > Kevin Spencer wrote:
    > >> This is done through the IIS Admin tool, not Windows. Web Site
    > >> Properties -
    > >> Home Directory Tab - Configure Button - Options Tab.
    > >>
    > >> --
    > >> HTH,
    > >>
    > >> Kevin Spencer
    > >> Microsoft MVP
    > >> .Net Developer
    > >> You can lead a fish to a bicycle,
    > >> but it takes a very long time,
    > >> and the bicycle has to *want* to change.
    > >>
    > >> "mohit" <> wrote in message
    > >> news:...
    > >> > Neither the root relative path nor the absolute path are working.
    > >> > could you please tell me how to configure windows to allow parent
    > >> > paths.
    > >> > Thanks
    > >> >
    > >> > Kevin Spencer wrote:
    > >> >> Your web server doesn't allow parent paths. You either have to use a
    > >> >> root-relative path, and absolute path, or configure your web server to
    > >> >> allow
    > >> >> parent paths.
    > >> >>
    > >> >> --
    > >> >> HTH,
    > >> >>
    > >> >> Kevin Spencer
    > >> >> Microsoft MVP
    > >> >> .Net Developer
    > >> >> You can lead a fish to a bicycle,
    > >> >> but it takes a very long time,
    > >> >> and the bicycle has to *want* to change.
    > >> >>
    > >> >> "mohit" <> wrote in message
    > >> >> news:...
    > >> >> > Hi,
    > >> >> > I am creating a web application in Web Matrix on the .NET
    > >> >> > framework.
    > >> >> > I have two directories :AddUser and FormAuth in a Directory P.
    > >> >> >
    > >> >> > AddUser contains a file AddUser.aspx
    > >> >> > FormAuth contains : Default.aspx , Users.xml , Login.aspx
    > >> >> >
    > >> >> > I have the following code :
    > >> >> >
    > >> >> > DataSet ds = new DataSet();
    > >> >> >
    > >> >> > String userFile = "../Users.xml";
    > >> >> >
    > >> >> > FileStream fs = new FileStream(Server.MapPath(userFile),
    > >> >> > FileMode.Open,FileAccess.Read);
    > >> >> > StreamReader reader = new StreamReader(fs);
    > >> >> > ds.ReadXml(reader);
    > >> >> > fs.Close();
    > >> >> >
    > >> >> >
    > >> >> > When I run it it gives the following exception :
    > >> >> >
    > >> >> > [HttpException (0x80004005): Cannot use a leading .. to exit above
    > >> >> > the
    > >> >> > top directory.]
    > >> >> > System.Web.Util.UrlPath.Reduce(String path) +581
    > >> >> > System.Web.Util.UrlPath.Combine(String basepath, String relative)
    > >> >> > +251
    > >> >> > System.Web.HttpRequest.MapPath(String virtualPath, String
    > >> >> > baseVirtualDir, Boolean allowCrossAppMapping) +192
    > >> >> > System.Web.HttpServerUtility.MapPath(String path) +61
    > >> >> > ASP.AddUser_aspx.Button1_Click(Object sender, EventArgs e) in
    > >> >> > F:\DC
    > >> >> > Downlaods(complete)\mohitag\MyProject\AddUser\AddUser.aspx:28
    > >> >> > System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83
    > >> >> >
    > >> >> > 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() +1263
    > >> >> >
    > >> >> > IF YOU HAVE SOME IDEA PLEASE TELL ME AS SOON AS POSSIBLE.
    > >> >> >
    > >> >> > Thank you very much
    > >> >> >
    > >> >

    > >
     
    mohit, Dec 21, 2005
    #7
  8. It's pretty simple really. The constructior for FileStream requires a file
    path to a file. This is not the same as a URL or virtual path. Now, you're
    running an ASP.Net application, which works in the context of a web server,
    and virtual directories. So, how you get the full file path to the file can
    be any number of ways. You can type it into your code as a literal string:

    string filePath = @"C:\inetpub\wwwroot\yourAppRoot\somefolder\somefile.xml";

    - or -

    string filePath =
    "C:\\inetpub\\wwwroot\\yourAppRoot\\somefolder\\somefile.xml";

    You can derive the file path from a web server virtual directory path, as
    long as the file is under the root folder of your ASP.Net application:

    string filePath = Server.MapPath("/somefolder/somefile.xml"); //
    root-relative

    string filePath = Server.MapPath("../somefolder/somefile.xml"); // relative
    to current Page

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    You can lead a fish to a bicycle,
    but it takes a very long time,
    and the bicycle has to *want* to change.



    "mohit" <> wrote in message
    news:...
    > Following your instructions when I give the absolute path it says that
    > the path is invalid and asks for virtual path.
    > When I give the virtual path it says that the path does not exist.I
    > have even configured my web server for the parent path.
    > This all is becoming very messy to me.I am unable to understand where
    > the major mistake is.
    >
    > Please guide me.
    >
    > Thank you.
    >
    > Kevin Spencer wrote:
    >> You have 4 distinctly different problems here:
    >>
    >> (1)
    >> > String userFile = "../Users.xml";
    >> >
    >> > FileStream fs = new FileStream(Server.MapPath(userFile),
    >> > FileMode.Open,FileAccess.Read);

    >>
    >> > Error is :Exception Details: System.Web.HttpException: Cannot use a
    >> > leading .. to exit above the top directory.

    >>
    >> This would indicate that the current HttpContext of the Page is in the
    >> root
    >> (top) directory of the app. The ".." indicates a directory above that
    >> one,
    >> which is below the top directory, and therefore outside the ASP.Net app.
    >> This is a security feature of ASP.Net. You can use a root-relative path
    >> instead, such as: "/Users.xml"
    >>
    >> (2)
    >> > String userFile = "FormsAuth/Users.xml"; or
    >> > "/FormsAuth/Users.xml"
    >> >
    >> > FileStream fs = new FileStream(Server.MapPath(userFile),

    >>
    >> > Error :Exception Details: System.IO.DirectoryNotFoundException: Could
    >> > not find a part of the path "F:\DC
    >> > Downlaods(complete)\mohitag\MyProject\AddUser\FormsAuth\Users.xml".

    >>
    >> The path that is indicated in the error message doesn't exist.
    >>
    >> (3)
    >> String userFile = "F:\DC
    >> > Downlaods(complete)\mohitag\MyProject\FormsAuth\Users.xml";
    >> >
    >> > FileStream fs = new FileStream(Server.MapPath(userFile),
    >> > FileMode.Open,FileAccess.Read);

    >>
    >> > Error : Compiler Error Message: CS1009: Unrecognized escape sequence

    >>
    >> The "\" character in C# is an escape sequence. You have to escape it with
    >> another "\" character (as in "\\" to represent a "\" character in a
    >> string.
    >>
    >> (4)
    >> You're programming by guesswork. This is the biggest problem of all. It
    >> will
    >> cost you beaucoups time. Do you have the Microsoft .Net SDK? You can
    >> download it for free from:
    >>
    >> http://msdn.microsoft.com/netframework/downloads/updates/default.aspx
    >>
    >> This page has links to the Framework SDK for both 1.1 and 2.0 framework
    >> versions.
    >>
    >> You'll save yourself a lot of time by using it. Ever since the first
    >> version
    >> of the Framework was released, I've spent about an hour a day on average
    >> reading in it.
    >>
    >> --
    >> HTH,
    >>
    >> Kevin Spencer
    >> Microsoft MVP
    >> .Net Developer
    >> You can lead a fish to a bicycle,
    >> but it takes a very long time,
    >> and the bicycle has to *want* to change.
    >>
    >>
    >> "mohit" <> wrote in message
    >> news:...
    >> >I have tried it. I am using IIS in Windows XP.
    >> > The errors are as following :
    >> >
    >> > if the code is : String userFile = "../Users.xml";
    >> >
    >> > FileStream fs = new FileStream(Server.MapPath(userFile),
    >> > FileMode.Open,FileAccess.Read);
    >> >
    >> >
    >> > Error is :Exception Details: System.Web.HttpException: Cannot use a
    >> > leading .. to exit above the top directory.
    >> >
    >> > If the code is : String userFile = "FormsAuth/Users.xml"; or
    >> > "/FormsAuth/Users.xml"
    >> >
    >> > FileStream fs = new FileStream(Server.MapPath(userFile),
    >> >
    >> >
    >> > Error :Exception Details: System.IO.DirectoryNotFoundException: Could
    >> > not find a part of the path "F:\DC
    >> > Downlaods(complete)\mohitag\MyProject\AddUser\FormsAuth\Users.xml".
    >> >
    >> > If the code is: String userFile = "F:\DC
    >> > Downlaods(complete)\mohitag\MyProject\FormsAuth\Users.xml";
    >> >
    >> > FileStream fs = new FileStream(Server.MapPath(userFile),
    >> > FileMode.Open,FileAccess.Read);
    >> >
    >> >
    >> > Error : Compiler Error Message: CS1009: Unrecognized escape sequence
    >> >
    >> > Thank you very much.
    >> >
    >> > Kevin Spencer wrote:
    >> >> This is done through the IIS Admin tool, not Windows. Web Site
    >> >> Properties -
    >> >> Home Directory Tab - Configure Button - Options Tab.
    >> >>
    >> >> --
    >> >> HTH,
    >> >>
    >> >> Kevin Spencer
    >> >> Microsoft MVP
    >> >> .Net Developer
    >> >> You can lead a fish to a bicycle,
    >> >> but it takes a very long time,
    >> >> and the bicycle has to *want* to change.
    >> >>
    >> >> "mohit" <> wrote in message
    >> >> news:...
    >> >> > Neither the root relative path nor the absolute path are working.
    >> >> > could you please tell me how to configure windows to allow parent
    >> >> > paths.
    >> >> > Thanks
    >> >> >
    >> >> > Kevin Spencer wrote:
    >> >> >> Your web server doesn't allow parent paths. You either have to use
    >> >> >> a
    >> >> >> root-relative path, and absolute path, or configure your web server
    >> >> >> to
    >> >> >> allow
    >> >> >> parent paths.
    >> >> >>
    >> >> >> --
    >> >> >> HTH,
    >> >> >>
    >> >> >> Kevin Spencer
    >> >> >> Microsoft MVP
    >> >> >> .Net Developer
    >> >> >> You can lead a fish to a bicycle,
    >> >> >> but it takes a very long time,
    >> >> >> and the bicycle has to *want* to change.
    >> >> >>
    >> >> >> "mohit" <> wrote in message
    >> >> >> news:...
    >> >> >> > Hi,
    >> >> >> > I am creating a web application in Web Matrix on the .NET
    >> >> >> > framework.
    >> >> >> > I have two directories :AddUser and FormAuth in a Directory P.
    >> >> >> >
    >> >> >> > AddUser contains a file AddUser.aspx
    >> >> >> > FormAuth contains : Default.aspx , Users.xml , Login.aspx
    >> >> >> >
    >> >> >> > I have the following code :
    >> >> >> >
    >> >> >> > DataSet ds = new DataSet();
    >> >> >> >
    >> >> >> > String userFile = "../Users.xml";
    >> >> >> >
    >> >> >> > FileStream fs = new FileStream(Server.MapPath(userFile),
    >> >> >> > FileMode.Open,FileAccess.Read);
    >> >> >> > StreamReader reader = new StreamReader(fs);
    >> >> >> > ds.ReadXml(reader);
    >> >> >> > fs.Close();
    >> >> >> >
    >> >> >> >
    >> >> >> > When I run it it gives the following exception :
    >> >> >> >
    >> >> >> > [HttpException (0x80004005): Cannot use a leading .. to exit
    >> >> >> > above
    >> >> >> > the
    >> >> >> > top directory.]
    >> >> >> > System.Web.Util.UrlPath.Reduce(String path) +581
    >> >> >> > System.Web.Util.UrlPath.Combine(String basepath, String
    >> >> >> > relative)
    >> >> >> > +251
    >> >> >> > System.Web.HttpRequest.MapPath(String virtualPath, String
    >> >> >> > baseVirtualDir, Boolean allowCrossAppMapping) +192
    >> >> >> > System.Web.HttpServerUtility.MapPath(String path) +61
    >> >> >> > ASP.AddUser_aspx.Button1_Click(Object sender, EventArgs e) in
    >> >> >> > F:\DC
    >> >> >> > Downlaods(complete)\mohitag\MyProject\AddUser\AddUser.aspx:28
    >> >> >> > System.Web.UI.WebControls.Button.OnClick(EventArgs e) +83
    >> >> >> >
    >> >> >> > 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() +1263
    >> >> >> >
    >> >> >> > IF YOU HAVE SOME IDEA PLEASE TELL ME AS SOON AS POSSIBLE.
    >> >> >> >
    >> >> >> > Thank you very much
    >> >> >> >
    >> >> >
    >> >

    >
     
    Kevin Spencer, Dec 21, 2005
    #8
  9. mohit

    mohit Guest

    I understood it.But I don't understand one thing that why my program is
    giving error.
    Actually with the constructor FileStream we should give virtual
    path.But when I provide
    it virtual path it gives the error that the path does not exist.That is
    what the major problem is.
    I have configured my web server too.

    Ideas ??

    Thank you.
     
    mohit, Dec 21, 2005
    #9
    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. Mark Hampton
    Replies:
    0
    Views:
    2,688
    Mark Hampton
    Jul 2, 2003
  2. OMNI GROUP

    ASP.NET/ EXCEPTIONAL/ NC

    OMNI GROUP, Jan 10, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    456
    OMNI GROUP
    Jan 10, 2006
  3. OMNI GROUP

    VB.NET/ EXCEPTIONAL OPPORTUNITY/ IN

    OMNI GROUP, Mar 8, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    366
    OMNI GROUP
    Mar 8, 2006
  4. mfolb
    Replies:
    12
    Views:
    669
    Oliver Wong
    Apr 3, 2006
  5. makuchaku
    Replies:
    5
    Views:
    352
Loading...

Share This Page