1

I'm trying to create a smmall Website for some Document to fill them out. It's a lot standard Information and i created an included textfile to read from. My problem is, that i don't know how to read from it, if i move the project somewhere else. Something like that maybe:

String path = "http://localhost:52179/source.txt";
        string[] myLines = File.ReadAllLines(path, Encoding.UTF8);
TechDuck
  • 17
  • 6
  • Where is source.txt actually located on your system/server? Use that path. – Broots Waymb Aug 07 '19 at 14:47
  • You need to get the relative path https://stackoverflow.com/questions/12335618/file-path-for-project-files – Train Aug 07 '19 at 14:48
  • 1
    You cannot use an url like that to read the file from server code. You need to use https://learn.microsoft.com/en-us/dotnet/api/system.web.httpserverutility.mappath?view=netframework-4.8 – Steve Aug 07 '19 at 14:48
  • It is not clear if you are running the two lines above from the server code-behind inside one of your aspx pages or if you are trying to read that file from a client machine using a browser or some sort of client software. Could you explain? – Steve Aug 07 '19 at 14:56
  • It is located in the Website directory, where my all sources(html, css etc.). – TechDuck Aug 07 '19 at 15:28
  • Thanks for the help, from everyody. It is in this case not possible, because i have to declare different values, to different keys, so i cannot put it in a for/foreach loop. Altough i could copy this file to the server and read from it, with the same Method i wrote in the question. – TechDuck Aug 08 '19 at 09:03

0 Answers0