2

i have a database where the datapath of docxfiles are saved..These datapath are in my hard drive..i want to show the docxfile exactly the same in my webpage..in my docxfile there may be some texts inside a table and there may be some images..i want to show the exact docxfile into my webpage..i don't know how to do it...

i have seen a code from retrieving data from database which are stored in my APP_DATA folder

@{
var dataFile = Server.MapPath("~/App_Data/Persons.docx");
Array userData = File.ReadAllLines(dataFile);
}

<!DOCTYPE html>
<html>
<body>

<h1>Reading Data from a File</h1>
@foreach (string dataLine in userData) 
{
foreach (string dataItem in dataLine.Split(',')) 
{@dataItem <text>&nbsp;</text>}
<br />
}
</body>
</html>

i don't know whether this will show the exact data with pictures or data inside the table that means how the data is written in the docxfile...

2 Answers2

0

Try it

protected void Page_Load(object sender, EventArgs e)
{
     var data = File.ReadAllText(Server.MapPath("~/App_Data/Persons.docx"));
     HiddenField1.Value = data.ToString();   
}

Here HiddenField1 is asp control in my case.

Follow below link to get more information

How To Write Binary Files to the Browser Using ASP.NET and Visual C# .NET

refer this link i hope it will help you. Preview Word files (docx) in HTML using ASP.NET

stackoverflow.com

Community
  • 1
  • 1
Govinda Rajbhar
  • 2,926
  • 6
  • 37
  • 62
0

Google for the code to convert the .docx to .pdf file and you can refer the following code part to show the pdf file in webpage.

                string strFileLocation = @"D:\PdfFile\Ref_12345.pdf";          
                Response.AddHeader("content-disposition", ";filename=\"" + strFileLocation + "\"");
                Response.ContentType = "application/pdf"; 
                Response.TransmitFile(strFileLocation);