Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Do you want to save or open this file?

Reply
Thread Tools

Do you want to save or open this file?

 
 
Derek
Guest
Posts: n/a
 
      11-24-2009
I am trying to print a Word document from with an ASP.Net 2005 application.
My code is:

Dim myFile As New FileInfo(fileName)
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" +
(UserSession.LoggedInUser.PrinterName + "^").Replace(" ", "$").Replace("\",
"~") + "Barcode.Doc")
Response.AddHeader("Content-Length", myFile.Length.ToString())
Response.ContentType = "application/msword"
Response.WriteFile(myFile.FullName)
Response.Flush()

When the code runs I am asked "Do you want to save or open this file?".

I click open and a macro runs in the word document and word closes down.

How can I by pass the dialog box and just print the document?
--
Derek
 
Reply With Quote
 
 
 
 
Patrice
Guest
Posts: n/a
 
      11-24-2009
You can't for safety reasons...


"Derek" <> a écrit dans le message de groupe
de discussion : B34A62D9-6F24-4FF3-BBDF-...
> I am trying to print a Word document from with an ASP.Net 2005
> application.
> My code is:
>
> Dim myFile As New FileInfo(fileName)
> Response.Clear()
> Response.AddHeader("Content-Disposition", "attachment; filename=" +
> (UserSession.LoggedInUser.PrinterName + "^").Replace(" ",
> "$").Replace("\",
> "~") + "Barcode.Doc")
> Response.AddHeader("Content-Length", myFile.Length.ToString())
> Response.ContentType = "application/msword"
> Response.WriteFile(myFile.FullName)
> Response.Flush()
>
> When the code runs I am asked "Do you want to save or open this file?".
>
> I click open and a macro runs in the word document and word closes down.
>
> How can I by pass the dialog box and just print the document?
> --
> Derek



 
Reply With Quote
 
 
 
 
Gregory A. Beamer
Guest
Posts: n/a
 
      11-24-2009
=?Utf-8?B?RGVyZWs=?= <> wrote in
news:B34A62D9-6F24-4FF3-BBDF-:

> When the code runs I am asked "Do you want to save or open this file?".
>
> I click open and a macro runs in the word document and word closes down.
>
> How can I by pass the dialog box and just print the document?


AFAIK, you can't do this in ASP.NET. The reason is simple: the code is on
hte server side and the application is opening on the client side. As a
Word doc can contain evil macros (while your print macro does not qualify
as evil, some people are not as nice), the user should always be prompted
so he can abort opening the document if it does not come from a trusted
source. This does not help you, of course.

The only option I can think of that might avoid this is setting up Word as
a MIME type, but even then I think you would need some corporate trust
policy to avoid save/open and force the open.

I could be partially incorrect on this, as I have not heavily invested in
Office/web automation, but the concept that the browser tries to save a
user from himself is sound.

If you want to retool so the file is printed from the server side, you have
some options, esp. with third party office libs. This can work in a
corporate environment, but would not work on a public website.

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Reply With Quote
 
Patrice
Guest
Posts: n/a
 
      11-24-2009
> You can't for safety reasons...

More precisely unless workstations are under your control. If they are you
could perhaps come up with a different scheme but you may still want to
double check you want to implement this. If allowed by the security zone in
which the site is, a web page could automate Word to open the file and print
it (but you may have an additional dialog to connect to the site that holds
the word document as Word will use its own connection)...

I believe you can also configure this at the mime type level but then it
would be a security issue for other sites as well...

So it's likely better to just live with the extra click.

--
Patrice




 
Reply With Quote
 
Patrice
Guest
Posts: n/a
 
      11-24-2009
> Under no circumstances should a web page ever try to automate Word or any
> of the other Office products.


Not server side but client side to print to the local printer.

That said this is mainly for completeness as IMO it would be really overkill
to avoid an additional click and it would have its own problem likely adding
additional clicks (such as authentication) unless you can configure every
settings just to achieve this very specific goal.

--
Patrice


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
repeating dialog box problem - "Do you want to open or save this f Shalom ASP General 3 05-29-2008 05:08 PM
Re: how to open a file in some application using Tkinter i am usingTKINTER to create GUI application i want to know how to open a worddocument in open office or any other applicatio Fredrik Lundh Python 1 01-09-2008 10:40 AM
Open A document without the Open/save/Cancel disloguw box Iain ASP .Net 1 04-09-2007 01:25 PM
Force browser to open a file (rather than save/open/cancel) tiewknvc9 Java 12 02-19-2007 08:21 PM
Closing the Open Save Dialog when user selects Save BusyBoy ASP .Net 2 10-31-2006 03:46 PM



Advertisments