 |
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

May 26th, 2007, 12:51 AM
|
Registered User
|
|
Join Date: May 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How to Open A Word Doc... using ASP .net
hi buddies....;)
i want to open a word document through asp.net using VB.net,
if someone has the Code 4 that plz. send me.....
Nikhil
|

May 27th, 2007, 12:40 AM
|
Friend of Wrox
|
|
Join Date: Aug 2006
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
mate the following is ur requested code :)
i'm a kind person.. so it also has how to open PDF and XLS.. and I don't know what else (actually i was too lazy to delete them :) anyway it's in C#.. so delete the (";"), define the string with dim, and use only one "/" in the string.. and the code will be perfect :).. and yeah.. remove the "{" "}"
:)
string strFileName = "C:\\FileName.doc" ;
// string strFileName = "C:\\temp.doc";
Response.ClearContent();
Response.ClearHeaders();
if (strFileName.Substring(strFileName.IndexOf('.') + 1).ToLower() == "pdf")
{
Response.ContentType = "application/PDF";
}
else
if (strFileName.Substring(strFileName.IndexOf('.') + 1).ToLower() == "doc")
{
Response.ContentType = "application/msword";
}
else
if (strFileName.Substring(strFileName.IndexOf('.') + 1).ToLower() == "xls")
{
Response.ContentType = "application/vnd.ms-excel";
}
else if (strFileName.Substring(strFileName.IndexOf('.') + 1).ToLower() == "ppt")
{
Response.ContentType = "application/vnd.ms-powerpoint";
}
else if (strFileName.Substring(strFileName.IndexOf('.') + 1).ToLower() == "txt")
{
Response.ContentType = "text/plain";
}
Response.WriteFile(strFileName);
Response.Flush();
Response.Close();
Response.Write("<script>window.print();window.clos e()</script>");
Nothing is impossible. The impossible only takes longer. "Digital Fortress, Dan Brown"
|

July 30th, 2007, 11:51 PM
|
Registered User
|
|
Join Date: Sep 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi
this code is helpful to me,
but here one problem, this code is run perfectly in IE and also open word document in a IE browser but in MOZILA it is not working perfectly, it will save .aspx page every time and word doc is open in Microsoft Word not in a mozila browser.
Thanks
Jigisha Gajjar
|

August 1st, 2007, 06:30 AM
|
Friend of Wrox
|
|
Join Date: Aug 2006
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
man can't understand your problem
Nothing is impossible. The impossible only takes longer. "Digital Fortress, Dan Brown"
|

August 1st, 2007, 08:05 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Quote:
quote:Originally posted by jigu_2811
...and word doc is open in Microsoft Word not in a mozila browser.
|
This is simply an issue with windows. Because I.E. is the MS browser, they are able to embed the office applications into the browser. Something like Adobe Reader behaves similarly because the plugin supports many browser types. But MS Office isn't that way. This is a shortcoming of non I.E. browsers you have to live with.
-Peter
|

April 19th, 2008, 02:37 PM
|
Registered User
|
|
Join Date: Apr 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
I also want to open doc and ppt files.I use a similar code.There is not a problem while openning files with msword.But I ppt files can not be opened.Powerpoint is opened but no slides are shown (I have been using office 2007).Here is my code which is written in a rowcommand event of a gridview:
protected void GridView1_RowCommand(Object src, GridViewCommandEventArgs e)
{
if (e.CommandName == "openDoc") {
GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Par ent;
string filePath = row.Cells[4].Text;
// Create New instance of FileInfo class to get the properties of the file being downloaded
FileInfo file = new FileInfo(filePath);
// Checking if file exists
if (file.Exists)
{
// Clear the content of the response
Response.ClearContent();
// LINE1: Add the file name and attachment, which will force the open/cance/save dialog to show, to the header
Response.AddHeader("Content-Disposition", "filename=" + file.Name);
// Add the file size into the response header
Response.AddHeader("Content-Length", file.Length.ToString());
// Set the ContentType
Response.ContentType = ReturnExtension(file.Extension.ToLower());
// Write the file into the response (TransmitFile is for ASP.NET 2.0. In ASP.NET 1.1 you have to use WriteFile instead)
file.IsReadOnly = true;
Response.TransmitFile(file.FullName);
// End the response
Response.End();
}
}
}
private string ReturnExtension(string fileExtension)
{
switch (fileExtension)
{
case ".htm":
case ".html":
case ".log":
return "text/HTML";
case ".txt":
return "text/plain";
case ".doc":
return "application/ms-word";
case ".zip":
return "application/zip";
case ".pdf":
return "application/pdf";
case ".ppt":
return "application/vnd.ms-powerpoint";
default:
return "application/octet-stream";
}
}
Thank you for your help.
|

May 8th, 2008, 01:21 PM
|
Registered User
|
|
Join Date: Feb 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am using Response.ContentType = "application/msword" in an asp.net application and it works fine with Word 2000 but anyone that has Word 2003 or Word 2007 installed it does not work. I have Word 2000 and 2003 installed on my machine and it works. Anybody know what I can do to make this work?
Brian
bkaralow@aol.com
|

March 5th, 2014, 05:45 AM
|
Registered User
|
|
Join Date: Feb 2014
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
RE: How to Open A Word
Hi, well one solution that you can try out is to convert DOC to a HTML file in .NET, and then show the HTML version on the client's browser.
This can work on any browser and regardless of what version of MS Office a client's machine has installed (actually MS Office installation would be unnecessary in this case).
|

March 31st, 2015, 03:45 AM
|
Registered User
|
|
Join Date: Mar 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by zaghmout
mate the following is ur requested code :)
i'm a kind person.. so it also has how to open PDF and XLS.. and I don't know what else (actually i was too lazy to delete them :) anyway it's in C#.. so delete the (";"), define the string with dim, and use only one "/" in the string.. and the code will be perfect :).. and yeah.. remove the "{" "}"
:)
string strFileName = "C:\\FileName.doc" ;
// string strFileName = "C:\\temp.doc";
Response.ClearContent();
Response.ClearHeaders();
if (strFileName.Substring(strFileName.IndexOf('.') + 1).ToLower() == "pdf")
{
Response.ContentType = "application/PDF";
}
else
if (strFileName.Substring(strFileName.IndexOf('.') + 1).ToLower() == "doc")
{
Response.ContentType = "application/msword";
}
else
if (strFileName.Substring(strFileName.IndexOf('.') + 1).ToLower() == "xls")
{
Response.ContentType = "application/vnd.ms-excel";
}
else if (strFileName.Substring(strFileName.IndexOf('.') + 1).ToLower() == "ppt")
{
Response.ContentType = "application/vnd.ms-powerpoint";
}
else if (strFileName.Substring(strFileName.IndexOf('.') + 1).ToLower() == "txt")
{
Response.ContentType = "text/plain";
}
Response.WriteFile(strFileName);
Response.Flush();
Response.Close();
Response.Write("<script>window.print();window.clos e()</script>");
Nothing is impossible. The impossible only takes longer. "Digital Fortress, Dan Brown"
|
Hi, how can I able to display the documents in browser.
The above code only viewing pdf document. Word and Excel documents are gets downloaded.
|
|
 |