Replies |
T.saravanan
Posted on: 3/8/2011 2:35:50 AM
|
Level: Silver | Status: [Member] [MVP] | Points: 25
|
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. |
Reply | Alert Moderator
|
Prabhakar
Posted on: 3/8/2011 4:42:40 AM
|
Level: Starter | Status: [Member] [MVP] | Points: 25
|
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. |
Reply | Alert Moderator
|
T.saravanan
Posted on: 3/8/2011 6:36:04 AM
|
Level: Silver | Status: [Member] [MVP] | Points: 25
|
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. |
Reply | Alert Moderator
|
Karthikanbarasan
Posted on: 3/8/2011 9:08:23 AM
|
Level: Silver | Status: [Member] [Moderator] [Microsoft_MVP] [MVP] | Points: 25
|
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. |
Reply | Alert Moderator
|
Karthikanbarasan, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|
Prabhakar
Posted on: 3/9/2011 5:28:40 AM
|
Level: Starter | Status: [Member] [MVP] | Points: 25
|
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. |
Reply | Alert Moderator
|
T.saravanan
Posted on: 3/9/2011 6:14:20 AM
|
Level: Silver | Status: [Member] [MVP] | Points: 25
|
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. |
Reply | Alert Moderator
|
Karthikanbarasan
Posted on: 3/9/2011 11:52:33 PM
|
Level: Silver | Status: [Member] [Moderator] [Microsoft_MVP] [MVP] | Points: 25
|
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. |
Reply | Alert Moderator
|
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. |
Reply | Alert Moderator
|
Vabjosh
Posted on: 10/20/2011 7:52:34 AM
|
Level: Starter | Status: [Member] | Points: 25
|
Karthikanbarasan, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|
Vivekjj
Posted on: 10/5/2012 8:51:37 AM
|
Level: Starter | Status: [Member] | Points: 25
|
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. |
Reply | Alert Moderator
|
Vivekjj
Posted on: 10/5/2012 9:08:36 AM
|
Level: Starter | Status: [Member] | Points: 25
|
Karthikanbarasan, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|
Vinay13mar
Posted on: 11/17/2012 10:12:45 AM
|
Level: Starter | Status: [Member] | Points: 25
|
Karthikanbarasan, if this helps please login to Mark As Answer. |
Reply | Alert Moderator
|
Sanmca4u
Posted on: 2/4/2013 12:05:35 AM
|
Level: Starter | Status: [Member] | Points: 25
|
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. |
Reply | Alert Moderator
|
Eva2012
Posted on: 2/4/2013 2:59:00 AM
|
Level: Starter | Status: [Member] | Points: 25
|
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. |
Reply | Alert Moderator
|