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("\\so开发者_开发百科me unc path\\TextFile1.txt");
var stream = new StreamReader(filepath);
return File(stream.ReadToEnd(), "text/plain");
}
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.
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");
精彩评论