本文介绍了在网页中显示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);
}
}
推荐答案
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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!