Friday 19 July 2013

Open Word File Directly on Client's PC without Displaying Save Dialogue Box

Open Word File Directly on Client's PC without Displaying Save Dialogue Box


So Here I am with a trick to open the Word File directly on button click event without interrupting the user with that annoying Save Options Dialogue Box. So here is how we can do this,,,

Put a Button on your design page and write the following code on the button click event of that button control..




    protected void Button1_Click(object sender, EventArgs e)
    {
        string FullFilePath =Server.MapPath("WordFile\\demo.docx");
        FileInfo file = new FileInfo(FullFilePath);
        if (file.Exists)
        {
            Response.ContentType = "application/vnd.ms-word";
            Response.AddHeader("Content-Disposition", "inline; filename=\"" + file.Name + "\"");
            Response.AddHeader("Content-Length", file.Length.ToString());
            Response.TransmitFile(file.FullName);
        }
    }

1 comment:

  1. Hello, I am a spanish software developer and I would like to express a few words of thanks because you help me resolve a great problem in my JEE web application project. I have spent almos a week trying to fix an error originated by Internet Explorer.
    Thank you very much.
    Best wishes.

    ReplyDelete

Thank You for Your Comments. We will get back to you soon.

back to top