Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Do you want to save or open this file?

0 views
Skip to first unread message

Derek

unread,
Nov 24, 2009, 11:07:02 AM11/24/09
to
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

Patrice

unread,
Nov 24, 2009, 11:49:15 AM11/24/09
to
You can't for safety reasons...


"Derek" <De...@discussions.microsoft.com> a �crit dans le message de groupe
de discussion : B34A62D9-6F24-4FF3...@microsoft.com...

Gregory A. Beamer

unread,
Nov 24, 2009, 12:00:56 PM11/24/09
to
=?Utf-8?B?RGVyZWs=?= <De...@discussions.microsoft.com> wrote in
news:B34A62D9-6F24-4FF3...@microsoft.com:

> 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! |
*******************************************

Mark Rae [MVP]

unread,
Nov 24, 2009, 12:14:18 PM11/24/09
to
"Derek" <De...@discussions.microsoft.com> wrote in message
news:B34A62D9-6F24-4FF3...@microsoft.com...

> How can I by pass the dialog box and just print the document?

As Patrice and Gregory have correctly stated, you can't - I'd advise you not
to waste any more time trying...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Patrice

unread,
Nov 24, 2009, 12:35:24 PM11/24/09
to
> 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


Mark Rae [MVP]

unread,
Nov 24, 2009, 1:04:31 PM11/24/09
to
"Patrice" <http://scribe-en.blogspot.com/> wrote in message
news:eajVCySb...@TK2MSFTNGP02.phx.gbl...

> a web page could automate Word to open the file and print it

Under no circumstances should a web page ever try to automate Word or any of
the other Office products.

Office wasn't designed to be used this way, and Microsoft don't support it:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2

Note the "MORE INFORMATION" section, and specifically the paragraph in
bold...

Patrice

unread,
Nov 24, 2009, 1:30:48 PM11/24/09
to
> 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


0 new messages