473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

open msword from a web form

Hi,

Using C# web form in ASP.Net, how to open a MS Word application?
Thanks for help.

Jason
Nov 17 '05 #1
6 2896
please try;

http://msdn.microsoft.com/office/und...wordobject.asp

"Jason Huang" wrote:
Hi,

Using C# web form in ASP.Net, how to open a MS Word application?
Thanks for help.

Jason

Nov 17 '05 #2
hi,

Very simple, all you have to do is set the correct content-type and send the
file, use this code:

this.Response.Clear();
this.Response.ContentType = "application/octet-stream";
this.Response.Buffer = false;
this.Response.BufferOutput = false;

FileStream fs = new FileStream(Server.MapPath( currentname),
FileMode.Open, FileAccess.Read);
//StreamReader reader = new StreamReader( Server.MapPath( currentname));

Response.AddHeader("Content-Disposition", "attachment;
filename=\""+targetname + "\"");
Response.AddHeader("Content-Length", fs.Length.ToString());
fs.Close();

Response.WriteFile( Server.MapPath( currentname) );
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Jason Huang" <Ja************@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

Using C# web form in ASP.Net, how to open a MS Word application?
Thanks for help.

Jason

Nov 17 '05 #3
Thanks Ignacio,

It works fine. But when I have the FileAccess.Read changed to
FileAccess.ReadWrite, then it gives me an error message:
System.UnauthorizedAccessException.
I am using ASP.Net on my Windows XP sp2.
Any advice will be appreciated.

Jason

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> ¼¶¼g©ó¶l¥ó·s»D:e6**************@TK2MSFTNGP10.phx.g bl...
hi,

Very simple, all you have to do is set the correct content-type and send
the file, use this code:

this.Response.Clear();
this.Response.ContentType = "application/octet-stream";
this.Response.Buffer = false;
this.Response.BufferOutput = false;

FileStream fs = new FileStream(Server.MapPath( currentname),
FileMode.Open, FileAccess.Read);
//StreamReader reader = new StreamReader( Server.MapPath( currentname));

Response.AddHeader("Content-Disposition", "attachment;
filename=\""+targetname + "\"");
Response.AddHeader("Content-Length", fs.Length.ToString());
fs.Close();

Response.WriteFile( Server.MapPath( currentname) );
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Jason Huang" <Ja************@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

Using C# web form in ASP.Net, how to open a MS Word application?
Thanks for help.

Jason


Nov 17 '05 #4
In message <OL**************@TK2MSFTNGP10.phx.gbl>, Jason Huang
<Ja************@hotmail.com> writes
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
Using C# web form in ASP.Net, how to open a MS Word application?
Very simple, all you have to do is set the correct content-type and send
the file, use this code:

this.Response.Clear();
this.Response.ContentType = "application/octet-stream";
this.Response.Buffer = false;
this.Response.BufferOutput = false;

FileStream fs = new FileStream(Server.MapPath( currentname),
FileMode.Open, FileAccess.Read);
//StreamReader reader = new StreamReader( Server.MapPath( currentname));

Response.AddHeader("Content-Disposition", "attachment;
filename=\""+targetname + "\"");
Response.AddHeader("Content-Length", fs.Length.ToString());
fs.Close();

Response.WriteFile( Server.MapPath( currentname) );

It works fine. But when I have the FileAccess.Read changed to
FileAccess.ReadWrite, then it gives me an error message:
System.UnauthorizedAccessException.
I am using ASP.Net on my Windows XP sp2.
Any advice will be appreciated.


That's probably just permissions, however enabling write access to the
file will not do you any good.

You can't write it by this mechanism. It isn't opening Word on the
server, it is sending the content of the file to the user's browser,
where it is opened by Word. It's equivalent to giving the user a url to
download the word document.

--
Steve Walker
Nov 17 '05 #5
Thanks Steve,

But, is it possible to write the word document and save it on the server?
given in the ASP.Net environment.
Jason

"Steve Walker" <st***@otolith.demon.co.uk>
???????:yj**************@otolith.demon.co.uk...
In message <OL**************@TK2MSFTNGP10.phx.gbl>, Jason Huang
<Ja************@hotmail.com> writes
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>

Using C# web form in ASP.Net, how to open a MS Word application? Very simple, all you have to do is set the correct content-type and send
the file, use this code:

this.Response.Clear();
this.Response.ContentType = "application/octet-stream";
this.Response.Buffer = false;
this.Response.BufferOutput = false;

FileStream fs = new FileStream(Server.MapPath( currentname),
FileMode.Open, FileAccess.Read);
//StreamReader reader = new StreamReader( Server.MapPath(
currentname));

Response.AddHeader("Content-Disposition", "attachment;
filename=\""+targetname + "\"");
Response.AddHeader("Content-Length", fs.Length.ToString());
fs.Close();

Response.WriteFile( Server.MapPath( currentname) );

It works fine. But when I have the FileAccess.Read changed to
FileAccess.ReadWrite, then it gives me an error message:
System.UnauthorizedAccessException.
I am using ASP.Net on my Windows XP sp2.
Any advice will be appreciated.


That's probably just permissions, however enabling write access to the
file will not do you any good.

You can't write it by this mechanism. It isn't opening Word on the server,
it is sending the content of the file to the user's browser, where it is
opened by Word. It's equivalent to giving the user a url to download the
word document.

--
Steve Walker

Nov 17 '05 #6
In message <OZ**************@TK2MSFTNGP15.phx.gbl>, Jason Huang
<Ja************@hotmail.com> writes
"Steve Walker" <st***@otolith.demon.co.uk>
???????:yj**************@otolith.demon.co.uk...
In message <OL**************@TK2MSFTNGP10.phx.gbl>, Jason Huang
<Ja************@hotmail.com> writes
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
> Using C# web form in ASP.Net, how to open a MS Word application? It works fine. But when I have the FileAccess.Read changed to
FileAccess.ReadWrite, then it gives me an error message:
System.UnauthorizedAccessException.
I am using ASP.Net on my Windows XP sp2.
Any advice will be appreciated.
You can't write it by this mechanism. It isn't opening Word on the server,
it is sending the content of the file to the user's browser, where it is
opened by Word. It's equivalent to giving the user a url to download the
word document.

But, is it possible to write the word document and save it on the server?
given in the ASP.Net environment.


Possible, yes. Not a good idea, though. You can automate Word from C#
server-side using COM interop, but you really shouldn't do so.

Here's a Microsoft kb article explaining how to, why not, and pointing
out some alternatives. It's ASP focused, but it also applies to ASP.NET.

http://support.microsoft.com/default...;EN-US;q257757

--
Steve Walker
Nov 17 '05 #7

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

Similar topics

0
by: Tom Gao | last post by:
hi guys I'm trying to export an aspx page to msword. ############# I know you can do Response.Clear(); Response.ContentType="application/msword";
0
by: staleb | last post by:
Hi I want to open a MSWord document on the clients PC/MSWord, the solution I use now is this: <script language=vbscript runat=Server> <!-- sub OpenDoc(strLocation) set objWord =...
0
by: Steve Chatham | last post by:
I am stuck on this. It ought to be a simple reason as to why this is problematic, in that it works on smaller groups of data (say under 40 records), but doesn't on larger groups of records (40+)....
4
by: Simon Cheng | last post by:
Hi, How do I open a Word or Excel document inside an event handler (e.g., Page_Load())? Thanks, Simon
6
by: Peter | last post by:
I have to write a ASP.NET application that creates MSWord document from a template and populated with data from the webpage. (Templates can reside on the server or client's hard drive.) What is...
7
by: rinku123 | last post by:
suppose in vb form are more then one textbox which is contain data and i want i click command button it save in msword file and it can replace many times suppose just like we make report). i have...
0
by: jayasabari | last post by:
Hai, I am reading the content form the msword file and displaying(writing) in aspx page(i.e., .net page). The content is displaying but some symbole is displaying My codding: ...
1
by: deegeorge | last post by:
Hi, I want to export crystal report from ASP .Net in word format. I am able to export crystal report but it dosen't give be the Word toolbar as we can see in when Msword document is opened....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
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...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.