Show a word document content in asp.net page

Posted by Karthikanbarasan under ASP.NET AJAX on 3/8/2011 | Points: 10 | Views : 86800 | Status : [Member] [Moderator] [Microsoft_MVP] [MVP] | Replies : 16
Hi,

can any one help me in this architecture. I have a requirement like, i have a webpage where i need to show a word document content. Like i can select a file from the word document and contents of the work document should be shown in the webpage.

Is there any option for any control to do this?

Thanks
Karthik
www.f5Debug.net



Responses

Posted by: T.saravanan on: 3/8/2011 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Karthik,

Try this Code...
FileInfo file = new FileInfo("Your FilePath");

Response.ClearContent();
Response.AddHeader("Content-Disposition", "inline;filename=" + file.Name);
Respone.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/msword";
Reponse.TransmitFile(file.FullName);
Response.End();


Cheers :)


Thanks,
T.Saravanan

Karthikanbarasan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 3/8/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi T.saravanan,

that's a gud code i also try it . . but that code word file are open in m.s.word . . i think real problem to show word file content in webpage. .

suggest some thing . .

Best Regard's
Prabhakar

Karthikanbarasan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 3/8/2011 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Just read the word file into string then to use the string object into page.
Try this..
using Microsoft.Office.Interop.Word;

private void readFileContent(string path)
{
ApplicationClass wordApp = new ApplicationClass();
object file = path;
object nullobj = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(
ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
string sFileText = doc.Content.Text;
doc.Close(ref nullobj, ref nullobj, ref nullobj);
wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);
Response.Write(sFileText);
}

The above code is refer from..http://www.daniweb.com/web-development/aspnet/threads/265281

Note: If the word file have an image (or) using Tables,Bullets & Numbering means those can not shown in a page.




Thanks,
T.Saravanan

Karthikanbarasan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 3/8/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi Saravanan,

Thanks for the code... but my issue is i have a word document with contents and the image... i want to show that word document in a web page using asp.net... Is there any control availalbe to show this type?

Thanks
Karthik
www.f5Debug.net

Karthikanbarasan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhu.b.rokkam on: 3/8/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Check this link this will help you ...
http://support.microsoft.com/?id=304662

Thanks and Regards
Madhu

Karthikanbarasan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 3/9/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi T.saravanan . .

your code is working fine .. but after one change .

in this line you enter 12 parameters . . but in asp.net want 16 parameters
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open( ref file, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);

my ruining code in asp.net


ApplicationClass wordApp = new ApplicationClass();

object file = path;

object nullobj = System.Reflection.Missing.Value;

Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(

ref file, ref nullobj, ref nullobj,

ref nullobj, ref nullobj, ref nullobj,

ref nullobj, ref nullobj, ref nullobj,

ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);



doc.ActiveWindow.Selection.WholeStory();

doc.ActiveWindow.Selection.Copy();

string sFileText = doc.Content.Text;

doc.Close(ref nullobj, ref nullobj, ref nullobj);

wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);

Response.Write(sFileText);


Best Regard's
Prabhakar

Karthikanbarasan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 3/9/2011 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Prabhakar,

Thanks for point out the error.Now i change it in my post.
Once again thanks...

Thanks,
T.Saravanan

Karthikanbarasan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 3/9/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Thanks all for the code... let me check it out!!!

Thanks
Karthik
www.f5Debug.net

Karthikanbarasan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kiran_ramisetti on: 8/4/2011 [Member] Starter | Points: 25

Up
0
Down
I want to open Bindary file of Word Document on browser, not from physical path, any one can help me out, with the given below code i can open PDF files in browser, but not other files.

CODE:

byte[] obFile = null;
obFile = (byte[])fds.Tables[0].Rows[0]["File"];
String aFileName = "abc";
Response.Expires = 0;
Response.ClearContent();
Response.Buffer = true;
Response.BufferOutput = true;
Response.ContentType = "application/msword;name=abc.docx";
Response.AddHeader("content-transfer-encoding", "binary");
Response.AddHeader("content-length", obFile.Length.ToString());
Response.AddHeader("Content-Disposition", "inline; filename=abc.docx";
Response.CacheControl = "public";
Response.ContentEncoding = System.Text.Encoding.GetEncoding(1251);
Response.OutputStream.Write(obFile, 0, obFile.Length);
Response.End();

Anyone Help me out this please.

Karthikanbarasan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vabjosh on: 10/20/2011 [Member] Starter | Points: 25

Up
0
Down
hi Karthikanbarasan
can you please tell me what was the solution for this question,
i very eager to read that.
http://forums.asp.net/p/1732149/4646774.aspx/1?Hey+hi+friends+any+one+can+tell+me+how+could+i+retrieve+binary+byte+word+document+and+show+in+web+browser
this is what i want to do,if any buddy can solve it i will be greatful for him

vabjosh

Karthikanbarasan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vivekjj on: 10/5/2012 [Member] Starter | Points: 25

Up
0
Down
Hi its working thanks,but how show a same format which we are view.like word file i need show means any control is there .(ex: gmail while we are view the document means its opening like same format know like that)... Thanks

Karthikanbarasan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vivekjj on: 10/5/2012 [Member] Starter | Points: 25

Up
0
Down
its working thanks

Karthikanbarasan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vinay13mar on: 11/17/2012 [Member] Starter | Points: 25
Posted by: Sanmca4u on: 2/4/2013 [Member] Starter | Points: 25

Up
0
Down
Hi when i am executing this code it is throwing a invalid path,can u please suggest me how to give the pathe inside file info method

Karthikanbarasan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Eva2012 on: 2/4/2013 [Member] Starter | Points: 25

Up
0
Down
Try this word component: http://netword.codeplex.com/ , it can show word file on webpage and convert webpage content to word file.

        private void button1_Click(object sender, EventArgs e)

{
//Create word document
Document document = new Document();
document.LoadFromFile(@"..\wordtohtml.doc");

//Save doc file to html
document.SaveToFile("toHTML.html", FileFormat.Html);
WordDocViewer("toHTML.html");
}

private void WordDocViewer(string fileName)
{
try
{
System.Diagnostics.Process.Start(fileName);
}
catch { }
}


Karthikanbarasan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naomiandika on: 9/26/2013 [Member] Starter | Points: 25

Up
0
Down
Well lots of codes you got here. Really remarkable.
<a href="http://mobiritz.com">mobi ritz</a>


Karthikanbarasan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response