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.

Remove this is line of code:
Response.AppendHeader("content-disposition", "attachment; filename=" + name);
Regards
Khaled

thanks Khaled for reply
if i removed this line, it would work fine with some file types (e.g. .doc), but with others e.g.(.txt, .log etc...) it open the file entire the explorer and with other type (e.g. .xls) it prombt the user to Open, Save or Cancel.

if there is solution for this issue, plz send me
and thank you Khaled again
(JAZAK ALLAH KHAIRAN) ;)

thanks Khaled for reply
if i removed this line, it would work fine with some file types (e.g. .doc), but with others e.g.(.txt, .log etc...) it open the file entire the explorer and with other type (e.g. .xls) it prombt the user to Open, Save or Cancel.

if there is solution for this issue, plz send me
and thank you Khaled again
(JAZAK ALLAH KHAIRAN) ;)

than why not adding links to your files in place of adding this download code.

Khaled

Thank you again, Khaled
i tried to do that but the same result is recieved that it works nice with some files but not all.
i really dont know what can i do.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.