Hi,
I want to display Microsoft Word or PDF file in webpage and it should not be downloadable like this site we post our articles in word file and it display in well formated just like i want to do. Kindly help to solve it.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Jan 3, 2014, 1:15 AM EST
http://www.aspsnippets.com/Articles/Display-Word-document-on-web-page-in-ASP.Net.aspx
Megan Foster18 reputationPosted Feb 10, 2015, 11:51 PM EST
protected void viewArticleHtml_Click(object sender, EventArgs e) { var document = DocumentModel.Load(Server.MapPath("~/Articles/Sample.docx")); using (var stream = new MemoryStream()) { document.Save(stream, new HtmlSaveOptions() { EmbedImages = true }); stream.WriteTo(this.Response.OutputStream); this.Response.Flush(); this.Response.SuppressContent = true; } }Also you can achieve the Word document's conversion to PDF with C# in similar manner, but instead of writing to a Response you can redirect it, like the following:
protected void viewArticlePdf_Click(object sender, EventArgs e) { if (!File.Exists(Server.MapPath("~/Articles/Sample.pdf"))) DocumentModel.Load(Server.MapPath("~/Articles/Sample.docx")) .Save(Server.MapPath("~/Articles/Sample.pdf")); var redirectUrl = string.Format("{0}://{1}{2}{3}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Host, HttpContext.Current.Request.Url.Port == 80 ? string.Empty : ":" + HttpContext.Current.Request.Url.Port, "/Articles/Sample.pdf"); this.Response.Redirect(redirectUrl); }