Hi,
My web page contains two button i.e
Collapse | Copy Code
<asp:button id="btnOpenword" runat="server" text="OpenFile">
<asp:button id="btnNext" runat="server" text="Next" visible="false">
when i click on the OpenFile Button i need to open the word document and also below the Next button should visible to the user.
so i write some code but it's working to open the word document, but it's not visible the Next button to the user.
Collapse | Copy Code
btnNext.Visible = true;
FileInfo file = new FileInfo("filename.doc");
Response.ClearContent();
Response.AddHeader("Content-Disposition", "inline;filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/msword";
Response.TransmitFile(file.FullName);
Response.End();
Plese give me solution it's urgent.
Thanks ,
Suresh
Opening MS Word Document in asp.net
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
John Glenn26 pointsPosted Mar 2, 2012, 1:24 AM EST
here is a sample ASP.NET export to Word code with this C# / VB.NET Word component. Hope it helps!
// Use the component in free mode. ComponentInfo.SetLicense("FREE-LIMITED-KEY"); // Create a new empty document. DocumentModel document = new DocumentModel(); // Add document content. document.Sections.Add(new Section(document, new Paragraph(document, "Hello World!"))); // Microsoft Packaging API cannot write directly to Response.OutputStream. // Therefore we use temporary MemoryStream. using (MemoryStream documentStream = new MemoryStream()) { document.Save(documentStream, SaveOptions.DocxDefault); // Stream file to browser. Response.Clear(); Response.ContentType = "application/vnd.openxmlformats"; Response.AddHeader("Content-Disposition", "attachment; filename=Document.docx"); documentStream.WriteTo(Response.OutputStream); Response.End(); }