Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
3.33/5 (3 votes)
See more:
as i have tried it like below
C#
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);  
        }  
    }  
Posted
Comments
rakesh1503 22-Feb-12 13:09pm    
I want to display the document in web page only.requirement is not Open or Save the document

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
 
Share this answer
 
Comments
Wonde Tadesse 20-Feb-12 22:21pm    
5+
Sergey Alexandrovich Kryukov 20-Feb-12 22:44pm    
Thank you, Wonde.
--SA
thatraja 20-Feb-12 22:59pm    
5
Sergey Alexandrovich Kryukov 20-Feb-12 23:07pm    
Thank you, Raja.
--SA
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:

C#
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(filepath);
Response.ContentType = "application/msword";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);


Good luck,
OI
 
Share this answer
 
v3
Comments
Wonde Tadesse 20-Feb-12 22:21pm    
5+
Orcun Iyigun 21-Feb-12 10:07am    
Thank you Wonde.
thatraja 20-Feb-12 22:59pm    
5
Orcun Iyigun 21-Feb-12 10:07am    
Thank you thatraja
Aditya Chauhan 1-Jun-15 4:44am    
In this section we can use path from the database ?
if any one use this then tell me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900