0

i am trying to display a textfile from a server location in the network but does not work?

  public ActionResult ShowFile()
    {
        string filepath = Server.MapPath("\\some unc path\\TextFile1.txt");

        var stream = new StreamReader(filepath);
        return File(stream.ReadToEnd(), "text/plain");

    }
1
  • 1
    Your backslashes are under-escaped. Commented May 9, 2011 at 14:42

2 Answers 2

2

The Problem is Server.MapPath("\\some unc path\\TextFile1.txt"); The file isn't located in your server document directory, so the mapping will fail. You have an absolute path, so use this in your StreamReader or give it directly to the File() method.

Also your path is incorrect. See the other post.

Sign up to request clarification or add additional context in comments.

1 Comment

I didn't notice that. There are also a bunch of other problems.
1

The File method takes a stream or filename; you're trying to pass it the file contents.
Change it to

return File(@"\\some unc path\TextFile1.txt", "text/plain");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.