473,698 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error in opening a word document from a web application

Hi,
I have to open a word document from my aspx page.The Page_Load method
contains the following code

System.IO.TextW riter tx = Response.Output ;
System.IO.Strea mReader sr = new System.IO.Strea mReader(this.Pa th);
Response.Conten tType = "applicatio n/msword";
tx.Write(sr.Rea dToEnd());
sr.Close();

Just to give more information, I have a First.aspx page which contains
a link to the Second.aspx page passing the complete path value. The
Page_Load method of Second.aspx page was shown above.
If I click the link, FileOpen dialog comes up and asks me for open,save
and cancel options. If I click Open, Microsoft Word opens and greets me
with a message: "Microsoft word needs a converter to display this file
correctly".If I click Cancel, then it is asking for me to select an
encoder.
What is the error? Am I doing the right thing in the Page_Load method.
I have MS Office 2003 installed and my IIS version is 5.1

I would be grateful for any help

Jan 23 '07 #1
4 2137
Sunil,

I think you are not writting the word document to the Response object. Pls
have a look at the sample code which i'v done before ...

string name = "your filename.doc";
Response.ClearH eaders();

Response.ClearC ontent();

Response.Conten tType = "applicatio n/vnd.ms-word";

Response.Append Header( "content-disposition","i nline;filename= " + name );

Response.WriteF ile(Server.MapP ath("name"));
// taking into consideration your word is in the root application folder
Response.End();

The above code worked for me
--
Thanks & Regards,
Mark Nelson
"sunil" wrote:
Hi,
I have to open a word document from my aspx page.The Page_Load method
contains the following code

System.IO.TextW riter tx = Response.Output ;
System.IO.Strea mReader sr = new System.IO.Strea mReader(this.Pa th);
Response.Conten tType = "applicatio n/msword";
tx.Write(sr.Rea dToEnd());
sr.Close();

Just to give more information, I have a First.aspx page which contains
a link to the Second.aspx page passing the complete path value. The
Page_Load method of Second.aspx page was shown above.
If I click the link, FileOpen dialog comes up and asks me for open,save
and cancel options. If I click Open, Microsoft Word opens and greets me
with a message: "Microsoft word needs a converter to display this file
correctly".If I click Cancel, then it is asking for me to select an
encoder.
What is the error? Am I doing the right thing in the Page_Load method.
I have MS Office 2003 installed and my IIS version is 5.1

I would be grateful for any help

Jan 23 '07 #2

Mark Nelson wrote:
Sunil,

I think you are not writting the word document to the Response object. Pls
have a look at the sample code which i'v done before ...

string name = "your filename.doc";
Response.ClearH eaders();

Response.ClearC ontent();

Response.Conten tType = "applicatio n/vnd.ms-word";

Response.Append Header( "content-disposition","i nline;filename= " + name );

Response.WriteF ile(Server.MapP ath("name"));
// taking into consideration your word is in the root application folder
Response.End();

The above code worked for me
--
Thanks & Regards,
Mark Nelson

I am writing into the Response object using a text writer

System.IO.TextW riter tx = Response.Output ;
System.IO.Strea mReader sr = new System.IO.Strea mReader(this.Pa th);
Response.Clear( );
Response.Conten tType = "applicatio n/msword";
tx.Write(sr.Rea dToEnd());
sr.Close();

The same thing works for other files like htm,txt files with
Response.Conten tType set properly.
The problem using your code is that my file is not on IIS. So I cannot
use Server.Map()
The path that I refer is a complete path to a Word document in the file
system of the local machine
Any suggestions?
Thanks for the response

Jan 23 '07 #3
I am writing into the Response object using a text writer

That might be your problem? A word file isn't a text file, try a
StreamWriter instead.
The problem using your code is that my file is not on IIS. So I cannot
use Server.Map()
Use a normal path then;

Response.WriteF ile(@"c:\somefo lder\somefile.d oc");
Jan 23 '07 #4

Aidy wrote:
I am writing into the Response object using a text writer

That might be your problem? A word file isn't a text file, try a
StreamWriter instead.
The problem using your code is that my file is not on IIS. So I cannot
use Server.Map()

Use a normal path then;

Response.WriteF ile(@"c:\somefo lder\somefile.d oc");
Response.WriteF ile worked for me. Initially, I had thought that it
works only for files on the server.
Thanks for such a tip.

Jan 23 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5583
by: Andy Davis | last post by:
I have set up a mail merge document in Word 2003 which gets its data from my Access 2000 database. I want to set up a button on a form that: 1. runs the query to provide the dat for the merge document in Word; 2. opens the document and runs the merge process for the new data. I have managed to write the code to perform step 1 ok, but I'm having trouble with step 2. It opens the word document fine but does not perform the mail merge of...
1
1713
by: Elizabeth Harmon | last post by:
Hi All I am attempting to open a Word App from a web page and so far everything works (After reconfig of dcomcnfg for Microsoft Word Document). I have one minor problem, i cannot get the application to become visible **********What am i doing wrong? is there something else that needs to be done to make the application visible? I am using windows 2000 and Word 2002 thanks in advance
0
4910
by: Sivaraman.S | last post by:
Issue : When I am trying to open a Word Document or a Template from a Web Application (ASP.NET Web page - Language Used VB.NET Visual Studio Version 2003) using Word.ApplicationClass (Refering Word 11.0 Library), I am getting the following Errror: Could not open Macro storage. (System.Runtime.ComExeception) When I am Opening the word document from a Windows Application, It is
7
3212
by: mkorch17 | last post by:
Hello, I have a server with a Word document and an Access database on it. I also have an ASP page running on the server. The Word document contains a mail merge with the Access database. What I want to do is open the merged Word document from the ASP page when a button is clicked. I have tried several things including some scripting that I found on the internet. This scripting works, however it opens the merged document on the...
2
3374
by: Colin Halliday | last post by:
I have a Word 2003 mail merge main document (form letter) that is linked to another Word document data source for the mail merge. If I open this doc using the Word GUI, it first asks me to confirm that I want to run a query to select the data from the data source file, then it opens the form letter fine. I can preview the merged records and complete a merge to a new document. I have a VB 2006 project (.net framework 2.0) which opens the...
5
2563
by: Cedric | last post by:
Hi Folks, I'm wondering if someone has already succeed to open a word2000 document located on server side with javascript code executed by a web browser on client side. In fact, i make it without any problem when the client use Word XP & 2003 but no result with Word 2000. Any suggestions are welcomed,
3
4882
by: Csaba Gabor | last post by:
If I do not have the indicated Word document open (on my Win XP Pro machine with PHP 5.2), the following will open and display it: <?php $path = "c:\\path\\to\\word\\document\\mydoc.doc"; $doc = new COM($path); $doc->Application->visible = true; ?> However, there will be several identical warnings (14 in number)
4
7738
by: Willis Wilson | last post by:
Platform: Access 2003 SP2 and Windows XP. I've tried a number of different scenarios and none of them seem to work The "OpenDataSource" statement gives a Run-time error 5922. Please help find my error. '******************************************** Dim wdApp As Word.Application, wd As Word.Document, strConnection As String Set wdApp = CreateObject("Word.Application")
0
1644
by: =?Utf-8?B?V2FubmFiZQ==?= | last post by:
I am creating a webpage and opening it as a Word document. Problem is that as I create one of the questions, some of the text is not appearing in the document as it should. As I step through it, I can see the text in my string builder variable, but once the page opens as a Word document, that same text is not showing. It seems to only be text that I am displaying as a result of some checkboxes I am trying to write to the page. Can anyone...
0
8673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9021
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7716
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3043
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.