<%@ Page
Title="Home
Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="HeaderContent"
runat="server"
ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent"
runat="server"
ContentPlaceHolderID="MainContent">
<h2>Testing opening word document from webpage.
</h2>
<asp:Button runat="server" ID="btnStart" Text="Click here" onclick="btnStart_Click"/>
</p>
</asp:Content>
//default.aspx.cs
using System;using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnStart_Click(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=Test.docx");
Response.ContentType = "application/ms-word";
//If you have sharepoint path then change here..
Response.TransmitFile(Server.MapPath("test.docx"));
Response.Flush();
Response.End();
}
}