Error: Could not find a part of the path / Reading and Writing to files in ASP.Net

Discussion in 'ASP .Net Security' started by TC, May 4, 2004.

  1. TC

    TC Guest

    Hello,

    I'm trying to read a text file located in the top folder of the virtual
    directory and I'm receiving the following error:

    "Could not find a part of the path"

    Below is the code that I'm using:

    string MyFile;
    MyFile =Request.ApplicationPath + "//sample1.txt";
    StreamReader srReader;
    srReader = new StreamReader(MyFile);
    txtMessage.Text = srReader.ReadLine();

    I have tried both "Windows" and "None" for "Authentication mode".

    Any ideas?

    Thanks & Regards,

    TC
    TC, May 4, 2004
    #1
    1. Advertising

  2. TC

    [MSFT] Guest

    Hello,

    Request.ApplicationPath will return a virtual path string like
    "/WebApplication1". However, StreamReader require a physical path like
    "C:\inetpub\webapplication1\sample.txt". To convert a virtual path to
    physical path, we can use MapPath method:

    MyFile =Server.MapPath(Request.ApplicationPath + "//sample1.txt");

    Hope this help,

    Luke
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    [MSFT], May 5, 2004
    #2
    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. TC
    Replies:
    3
    Views:
    26,136
    jessica
    May 19, 2004
  2. Gianfranco
    Replies:
    14
    Views:
    9,602
    Ollie
    Jul 28, 2005
  3. Replies:
    1
    Views:
    917
    Michael Nemtsev [MVP]
    Nov 13, 2007
  4. E. Kwong
    Replies:
    0
    Views:
    302
    E. Kwong
    Nov 6, 2006
  5. TC
    Replies:
    1
    Views:
    147
    [MSFT]
    May 5, 2004
Loading...

Share This Page