hi all,
i have a list of some files on the server.
i want to let the user choose a file from the list then click a button to open read-only version from this file without showing the popup message that ask user to Open, Save or Cancel.
this is because i don't want to give the user choice to download the file on his local machine.
the used code is as the following:
private void DownloadFile(string fname)
{
string myPath = Path.GetFullPath(fname);
string name = Path.GetFileName(myPath);
string ext = Path.GetExtension(myPath);
string type = "";
// set known types based on file extension
if (ext != null)
{
switch (ext.ToLower())
{
case ".htm":
case ".html":
type = "text/HTML";
break;
case ".txt":
type = "text/plain";
break;
case ".doc":
case ".rtf":
type = "Application/msword";
break;
case ".xls":
type = "Application/excel";
break;
default:
type = "text/plain";
break;
}
}
Response.Buffer = true;
Response.AppendHeader("content-disposition", "attachment; filename=" + name);
//Response.AppendHeader("Pragma","cache");
//Response.AppendHeader("Expires", "-1");
if (type != "")
Response.ContentType = type;
Response.WriteFile(myPath);
Response.End();
}
i searched about solve to this issue and i found some advices to change the parameter of the "Response.AppendHeader" function and i tried to follow it as u can see in the commented code but this was not helpful.
i want to solve this problem even the way is through IIS.
any1 has any advices i will be grateful if he/she helped me with it.
thanks for advance.
NAHR ELGANNAH.