-3

I have word files in my details folder and I want to display that word file in the browser. It gives me is not a valid virtual path error

string filename = "http://something.in/management/details/" + DS.Tables["Table"].Rows[0]["DETAILS"].ToString();

if (filename != "")
{
    string path = Server.MapPath(filename);
    System.IO.FileInfo file = new System.IO.FileInfo(path);
    if (file.Exists)
    {
        Response.Clear();
        Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
        Response.AddHeader("Content-Length", file.Length.ToString());
        Response.ContentType = "application/ms-word";
        Response.WriteFile(file.FullName);
        Response.End();
    }
    else
    {
        Response.Write("This file does not exist.");
    }
}
John Saunders
  • 157,405
  • 24
  • 229
  • 388
Hardik Mali
  • 59
  • 1
  • 1

1 Answers1

1

Server.MapPath(filename) will not accept a URL

See this and this for usage

e.g.

string filename = 
Server.MapPath("~/management/details/" + DS.Tables["Table"].Rows[0]["DETAILS"].ToString());

also you can use other types of uning Server.MapPath here

Community
  • 1
  • 1
Tyress
  • 3,421
  • 2
  • 18
  • 39