开发者

display file in asp.net mvc 2

开发者 https://www.devze.com 2023-03-04 04:34 出处:网络
i am trying to display a textfile from a server location in the network but does not work? public ActionResult ShowFile()

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");
0

精彩评论

暂无评论...
验证码 换一张
取 消