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

Ask a Question related to ASP.NET Web Services, Design and Development.

  1. #1

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

    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 Guest

  2. Similar Questions and Discussions

    1. "Could not find a part of the path… " error on IIS 6.0
      I have an ASP.NET web application running on a load-balanced Windows Server 2003 web farm running IIS 6.0, using Active Directory authentication. ...
    2. Reading from / Writing to text files out of Flash
      Does anyone know a Flash sample which reads and/or writes something to/from a text file? I read somewhere that this is possible in general but never...
    3. reading and writing files to local drives
      Hi, I've been looking into creating an app that reads an xml file and then saves it again to the local drive. Now I've tried the MMSave...
    4. Reading and writing files in PHP
      "Marc" <meelzooi2000@yahoo.com> wrote in message news:acad69df.0309010758.2de3fef5@posting.google.com... processing the file (not having written...
    5. Reading writing to INI files
      Hello, Are there any modules available that can read/write to INI files. Thanks in advance Saadat Saeed ...
  3. #2

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

    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 Guest

  4. #3

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

    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! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    [MSFT] Guest

  5. #4

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

    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! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)


    [MSFT] Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139