Downloaded document has disappeared by the time Word has opened

R

Rob Nicholson

We've implemented functionality to allow a user to download a document (any
document type) from the IIS server using the following code:

Response.Clear()
Response.ContentType = "application/x-msdownload"
Response.AddHeader("Content-Disposition", "attachment; filename=" &
System.IO.Path.GetFileName(FilePath))
Response.AddHeader("Content-Length", File.Length.ToString())
Response.WriteFile(FilePath)
Response.End()

When this response is sent back, IE prompts the user whether they want to
open, save or cancel the download. It works perfectly if they save the
document to their local hard drive and then open it. However, if they select
Open, the file downloads (quickly) but by the time Word opens, the copy in
temporary internet files has either disappeared or never saved in the first
place. Word displays an error about "The file could not be found".

I suspect it's something to do with caching but whilst I can find many posts
about stopping caching, I can't find any good examples in ASP.NET about
forcing the Word document to cache.

Any ideas?

Thanks, Rob.
 
G

Guest

It seems as if the content-type specifically says it is for downloading. Try
using "application/doc" for Word files. This will tell the browser to open
it. The user then can optionally save it locally.

Or, try setting the "content-expiration" setting for the directory in IIS to
expire in one minute(versus immediately). Word, PDF, and others have had a
problem being opened in the browser with expire-immediately.
 
S

Steven Cheng[MSFT]

Hi Rob,

I think you can try Brad's suggestion on adjusting the Content Type
property of your response object. Based on the code you provided, there
seems no other particular things except the content-type value. Generally,
we can always use the "application/octet-stream" for all binary data
streams.
If there're any other findings, please feel free to post here.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Thread-Topic: Downloaded document has disappeared by the time Word has
opened
| thread-index: AcWuaqCYbyNdCVghSemc2lRBU+nUxA==
| X-WBNR-Posting-Host: 129.54.8.45
| From: =?Utf-8?B?QnJhZCBSb2JlcnRz?= <[email protected]>
| References: <[email protected]>
| Subject: RE: Downloaded document has disappeared by the time Word has
opened
| Date: Wed, 31 Aug 2005 13:29:03 -0700
| Lines: 40
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:121534
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| It seems as if the content-type specifically says it is for downloading.
Try
| using "application/doc" for Word files. This will tell the browser to
open
| it. The user then can optionally save it locally.
|
| Or, try setting the "content-expiration" setting for the directory in IIS
to
| expire in one minute(versus immediately). Word, PDF, and others have had
a
| problem being opened in the browser with expire-immediately.
|
| "Rob Nicholson" wrote:
|
| > We've implemented functionality to allow a user to download a document
(any
| > document type) from the IIS server using the following code:
| >
| > Response.Clear()
| > Response.ContentType = "application/x-msdownload"
| > Response.AddHeader("Content-Disposition", "attachment; filename=" &
| > System.IO.Path.GetFileName(FilePath))
| > Response.AddHeader("Content-Length", File.Length.ToString())
| > Response.WriteFile(FilePath)
| > Response.End()
| >
| > When this response is sent back, IE prompts the user whether they want
to
| > open, save or cancel the download. It works perfectly if they save the
| > document to their local hard drive and then open it. However, if they
select
| > Open, the file downloads (quickly) but by the time Word opens, the copy
in
| > temporary internet files has either disappeared or never saved in the
first
| > place. Word displays an error about "The file could not be found".
| >
| > I suspect it's something to do with caching but whilst I can find many
posts
| > about stopping caching, I can't find any good examples in ASP.NET about
| > forcing the Word document to cache.
| >
| > Any ideas?
| >
| > Thanks, Rob.
| >
| >
| >
| >
| >
|
 
R

Rob Nicholson

using "application/doc" for Word files. This will tell the browser to open

The problem with this is that don't we then have to code/cater for every
different content type in the program and generate different content-types?
Or, try setting the "content-expiration" setting for the directory in IIS to
expire in one minute(versus immediately). Word, PDF, and others have had a
problem being opened in the browser with expire-immediately.

Ahh this might be more useful. Which directory do you set the expiry on as
the source folder varies?

Thanks, Rob.
 
R

Rob Nicholson

seems no other particular things except the content-type value. Generally,
we can always use the "application/octet-stream" for all binary data

Hi Steven,

We originally had "application/octet-stream" in there but the problem we
were having then on the test IIS 5 server was that the prompt to save never
appeared at all although it worked fine in the development environment.

Anyone know of a good reference for HTML responses esp. these binary ones?
The documentation in MSDN is very much at the reference level in describing
each of the methods/properties of Reponse.Cache, not necessarily what they
are used for.

Thanks, Rob
 
S

Steven Cheng[MSFT]

Hi Rob,

Thanks for your response. I'm really feeling strange that the
"Application/octet-stream" not work on your product server. The
"application/octet-stream" just means normal binary stream and is used
when you didn't sure on the specific content-type or your custom stream.
This must be a environment specific problem. Also, have you tried testing
the page from some other client machines to see whether this is a client
specific problem? For the specification on HTTP request/response message or
content-type, cache ,setting, you can refer to the HTTP 1.1 rfc , but I
think the asp.net has completely encapsulated most of them so that we don't
need to care about the underlying details.

Thanks,

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Rob Nicholson" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: Downloaded document has disappeared by the time Word has
opened
| Date: Thu, 1 Sep 2005 09:23:00 +0100
| Lines: 17
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.181
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.181
| Message-ID: <OW0#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: host217-45-2-106.in-addr.btopenworld.com 217.45.2.106
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:121650
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| > seems no other particular things except the content-type value.
Generally,
| > we can always use the "application/octet-stream" for all binary data
|
| Hi Steven,
|
| We originally had "application/octet-stream" in there but the problem we
| were having then on the test IIS 5 server was that the prompt to save
never
| appeared at all although it worked fine in the development environment.
|
| Anyone know of a good reference for HTML responses esp. these binary ones?
| The documentation in MSDN is very much at the reference level in
describing
| each of the methods/properties of Reponse.Cache, not necessarily what they
| are used for.
|
| Thanks, Rob
|
|
|
 
S

Steven Cheng[MSFT]

Hi Rob,

Have you got any further progress on this issue? If there're any further
things we can help, please feel free to post here. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| X-Tomcat-ID: 206198363
| References: <[email protected]>
<[email protected]>
<[email protected]>
<OW0#[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: (e-mail address removed) (Steven Cheng[MSFT])
| Organization: Microsoft
| Date: Fri, 02 Sep 2005 11:50:18 GMT
| Subject: Re: Downloaded document has disappeared by the time Word has
opened
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Lines: 64
| Path: TK2MSFTNGXA01.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:121977
| NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122
|
| Hi Rob,
|
| Thanks for your response. I'm really feeling strange that the
| "Application/octet-stream" not work on your product server. The
| "application/octet-stream" just means normal binary stream and is used
| when you didn't sure on the specific content-type or your custom stream.
| This must be a environment specific problem. Also, have you tried testing
| the page from some other client machines to see whether this is a client
| specific problem? For the specification on HTTP request/response message
or
| content-type, cache ,setting, you can refer to the HTTP 1.1 rfc , but I
| think the asp.net has completely encapsulated most of them so that we
don't
| need to care about the underlying details.
|
| Thanks,
|
| Regards,
|
| Steven Cheng
| Microsoft Online Support
|
| Get Secure! www.microsoft.com/security
| (This posting is provided "AS IS", with no warranties, and confers no
| rights.)
|
| --------------------
| | From: "Rob Nicholson" <[email protected]>
| | References: <[email protected]>
| <[email protected]>
| <[email protected]>
| | Subject: Re: Downloaded document has disappeared by the time Word has
| opened
| | Date: Thu, 1 Sep 2005 09:23:00 +0100
| | Lines: 17
| | X-Priority: 3
| | X-MSMail-Priority: Normal
| | X-Newsreader: Microsoft Outlook Express 6.00.3790.181
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.181
| | Message-ID: <OW0#[email protected]>
| | Newsgroups: microsoft.public.dotnet.framework.aspnet
| | NNTP-Posting-Host: host217-45-2-106.in-addr.btopenworld.com 217.45.2.106
| | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP14.phx.gbl
| | Xref: TK2MSFTNGXA01.phx.gbl
| microsoft.public.dotnet.framework.aspnet:121650
| | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| |
| | > seems no other particular things except the content-type value.
| Generally,
| | > we can always use the "application/octet-stream" for all binary data
| |
| | Hi Steven,
| |
| | We originally had "application/octet-stream" in there but the problem we
| | were having then on the test IIS 5 server was that the prompt to save
| never
| | appeared at all although it worked fine in the development environment.
| |
| | Anyone know of a good reference for HTML responses esp. these binary
ones?
| | The documentation in MSDN is very much at the reference level in
| describing
| | each of the methods/properties of Reponse.Cache, not necessarily what
they
| | are used for.
| |
| | Thanks, Rob
| |
| |
| |
|
|
 
R

Rob Nicholson

Have you got any further progress on this issue? If there're any further
things we can help, please feel free to post here. Thanks,

Not yet - it's still an open job. One interesting point we noticed is that
it behaves differently on the development PC to the pilot environment.

Cheers, Rob.
 
S

Steven Cheng[MSFT]

I'm sorry to hear that the problem remains. Also, since it's a environment
specific problem , that really make the troubleshooting a bit difficult.
have you also checked the IIS to see whether there're any custom headers
set in the site or virtual dir's HttpHeaders setting, you can also compare
your problem server with your development server. And here is the test code
which works well on myside:

private void DownloadFile()
{
Response.ClearHeaders();
Response.ClearContent();

Response.ContentType="application/octet-stream";

Response.AddHeader("content-disposition", "attachment;
filename=filename.ext");
Response.WriteFile(@"full file path");
Response.End();
}

You can also try testing it on your side. Hope helps.


Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Rob Nicholson" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<OW0#[email protected]>
<[email protected]>
<Kkgyb#[email protected]>
| Subject: Re: Downloaded document has disappeared by the time Word has
opened
| Date: Wed, 7 Sep 2005 15:40:09 +0100
| Lines: 9
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.181
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.181
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: host217-45-2-106.in-addr.btopenworld.com 217.45.2.106
| Path:
TK2MSFTNGXA01.phx.gbl!TK2MSFTFEED02.phx.gbl!tornado.fastwebnet.it!tiscali!ne
wsfeed1.ip.tiscali.net!news.maxwell.syr.edu!cyclone.bc.net!msrtrans!TK2MSFTN
GP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:122889
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| > Have you got any further progress on this issue? If there're any further
| > things we can help, please feel free to post here. Thanks,
|
| Not yet - it's still an open job. One interesting point we noticed is that
| it behaves differently on the development PC to the pilot environment.
|
| Cheers, Rob.
|
|
|
 
G

Guest

Hi Steven,

we have the same problem at our customers site with our application which
provides display of ad-hoc generated thumbnails and download of photos or
drawings after clicking on the thumbnails.

First I compared the Internet Settings in IE from our customer with the
settings at my computer. There is a Problem with the HTTP/1.0 compatibility
mode. This means, when you un-check all options about HTTP/1.1 in IE settings
no thumbnails are displayed and the downloaded bytes are 0 every time (e.g.
the requested document opens in the corresponding application such as
AutoCAD, Adobe Reader or Word, but then an error is displayed because there
were 0 bytes transferred).

We were able to reproduce this problem at our development site by
un-checking all HTTP/1.1 options. So good, so far. I telled our customer to
check the options, but with activated HTTP/1.1 support the error occurs... :(

In the sourcecode we set following parameters:
- ContentType to the correct Type by Extension of the corresponding file.
- Content-Disposition
- Content-Length

Do you have an idea? ;-)
Regards, Alex
 
E

Edwin Knoppert

Can't see th eorg. poster's msg.

Add:
Response.ClearHeaders()
Response.ClearContents()

Then add the desired headers
 
G

Guest

Here's our code snippet:

string filename = System.IO.Path.GetFileName(_strFileSource);
string mime = GetMIMEType(System.IO.Path.GetExtension(_strFileSource));
System.IO.FileInfo file = new System.IO.FileInfo(_strFileSource);

Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = mime;
Response.AddHeader("Content-Disposition","attachment; filename="+filename);
Response.AppendHeader("Content-Length", file.Length.ToString());
Response.Flush();
Response.WriteFile(file.FullName);
Response.Flush();

We use Response.ClearContent() and Response.ClearHeaders() already, but in
another order than your suggestion. Is this relevant to solve our problem? I
mean, must I call ClearHeaders() before ClearContent()???
 
E

Edwin Knoppert

Like i said, i was not able to read the orrg. msg from you.

here is a fragment, the actual loop is after this code:
..Response.Clear()
..Response.ClearContent()
..Response.ClearHeaders()
..Response.ContentType = "inline"
..Response.AppendHeader("Content-Disposition", "attachment; filename=" &
sFileNameOut)
..Response.AppendHeader("Content-Length", nTotalSize)
..Response.AppendHeader("Content-Transfer-Encoding", "BINARY")
..Response.Flush()

(i have loop here)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top