如何使用c#在asp.net的数据库中显示我的网页中的docxfile数据?

时间:2014-02-28 05:09:49

标签: c# asp.net

我有一个数据库,其中保存了docxfiles的数据路径..这些数据路径在我的硬盘中..我想在我的网页中显示完全相同的docx文件..在我的docxfile中,表格中可能有一些文本并且可能有一些图片..我想在我的网页上显示确切的docx文件..我不知道该怎么做...

我看过从数据库中检索数据的代码,这些代码存储在我的APP_DATA文件夹中

@{
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>

我不知道这是否会显示表格中的图片或数据的确切数据,这意味着如何在docx文件中写入数据......

2 个答案:

答案 0 :(得分:0)

试试吧

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

在我的案例中,HiddenField1 asp control为{{1}}。

按照以下链接获取更多信息

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

参考此链接我希望它能帮到你。 Preview Word files (docx) in HTML using ASP.NET

stackoverflow.com

答案 1 :(得分:0)

Google提供了将.docx转换为.pdf文件的代码,您可以参考以下代码部分在网页中显示pdf文件。

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