How to make relative path work with streamreader

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lightwalker19
    New Member
    • Apr 2012
    • 22

    How to make relative path work with streamreader

    Hello world! I've got a problem... im using a streamreader to read the text lines, but when i call the location of the text file it says:"Could not find a part of the path 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServe r\10.0\~\IDS\La ng\1.txt'." But i have a hyperlink with the same relative path, and it works :/ What am i doing wrong? i need this to work in a server in the future..

    Code:
          
    StreamReader reader = new StreamReader(@"~/IDS/Lang/1.txt");          
    string strAllFile=reader.ReadToEnd().Replace("\r\n","\n").Replace("\n\r","\n");
    string[] arrLines = strAllFile.Split(new char[] { '\n' });
    TextBox35.Text = arrLines[0] + arrLines[1] + arrLines[2];
                reader.Close();
  • lightwalker19
    New Member
    • Apr 2012
    • 22

    #2
    Found the solution, so simple it hurts xD

    Code:
     StreamReader reader = new StreamReader(Server.MapPath(@"~/IDS/Lang/1.txt"));

    Comment

    Working...