在网页中显示Word文档(asp.net) [英] Display word document in web page(asp.net)
本文介绍了在网页中显示Word文档(asp.net)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
就像我尝试过的那样
as i have tried it like below
protected void cmdView_Click(object sender, EventArgs e)
{
//ReadWriteData is a class
ReadWriteData rwd = new ReadWriteData();
string sb = rwd.ReadFile(@"C:\Documents and Settings\pa_mukeshk\My Documents\Visual Studio 2008\Execute 1.0.docx");
Session["FileData"] = sb;
Response.Redirect("~/HomePages/ViewPage.aspx", true);
//ReadWriteData class has below method
public string ReadFile(string path)
{
FileStream fstream = new FileStream(path, FileMode.Open, FileAccess.Read);
StreamReader sreader = new StreamReader(fstream, System.Text.Encoding.UTF8);
string sr = sreader.ReadToEnd();
return sr;
}
//on the load of ViewPage.aspx,i have
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string sb = (string)Session["FileData"];
Label lt = new Label();
lt.Text = sb.ToString();
myPanel.Controls.Add(lt);
}
}
推荐答案
请在以下页面上查看我过去的答案和其他答案:
如何在以下位置创建Word文档asp.net Windows应用程序 [如何在网站 [
Please see my past answers and other answers on these pages:
how can create word documents in asp.net windows application[^],
How to read a word file in a website[^].
—SA
在会话中,将文件路径传递到ViewPage.aspx.在您的!Postback方法的Viewpage.aspx页面中,加载会话值并使用以下代码:
In the session pass the file path to ViewPage.aspx. In page Viewpage.aspx in your !Postback method load the session value and use the following code:
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(filepath);
Response.ContentType = "application/msword";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
祝你好运,
OI
Good luck,
OI
这篇关于在网页中显示Word文档(asp.net)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文