473,714 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Downloaded document has disappeared by the time Word has opened

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.Conten tType = "applicatio n/x-msdownload"
Response.AddHea der("Content-Disposition", "attachment ; filename=" &
System.IO.Path. GetFileName(Fil ePath))
Response.AddHea der("Content-Length", File.Length.ToS tring())
Response.WriteF ile(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.


Nov 19 '05 #1
12 1944
It seems as if the content-type specifically says it is for downloading. Try
using "applicatio n/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.Conten tType = "applicatio n/x-msdownload"
Response.AddHea der("Content-Disposition", "attachment ; filename=" &
System.IO.Path. GetFileName(Fil ePath))
Response.AddHea der("Content-Length", File.Length.ToS tring())
Response.WriteF ile(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.


Nov 19 '05 #2
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 "applicatio n/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: AcWuaqCYbyNdCVg hSemc2lRBU+nUxA ==
| X-WBNR-Posting-Host: 129.54.8.45
| From: =?Utf-8?B?QnJhZCBSb2J lcnRz?= <Br************ *****@hotmail.c om>
| References: <uD************ **@TK2MSFTNGP15 .phx.gbl>
| 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: <0A************ *************** *******@microso ft.com>
| 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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GXA03.phx.gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1215 34
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| It seems as if the content-type specifically says it is for downloading.
Try
| using "applicatio n/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.Conten tType = "applicatio n/x-msdownload"
| > Response.AddHea der("Content-Disposition", "attachment ; filename=" &
| > System.IO.Path. GetFileName(Fil ePath))
| > Response.AddHea der("Content-Length", File.Length.ToS tring())
| > Response.WriteF ile(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.
| >
| >
| >
| >
| >
|

Nov 19 '05 #3
> using "applicatio n/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.
Nov 19 '05 #4
> seems no other particular things except the content-type value. Generally,
we can always use the "applicatio n/octet-stream" for all binary data


Hi Steven,

We originally had "applicatio n/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
Nov 19 '05 #5
Hi Rob,

Thanks for your response. I'm really feeling strange that the
"Applicatio n/octet-stream" not work on your product server. The
"applicatio n/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" <in******@commu nity.nospam>
| References: <uD************ **@TK2MSFTNGP15 .phx.gbl>
<0A************ *************** *******@microso ft.com>
<za************ **@TK2MSFTNGXA0 1.phx.gbl>
| 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: <OW************ **@TK2MSFTNGP14 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: host217-45-2-106.in-addr.btopenworl d.com 217.45.2.106
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP14.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1216 50
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| > seems no other particular things except the content-type value.
Generally,
| > we can always use the "applicatio n/octet-stream" for all binary data
|
| Hi Steven,
|
| We originally had "applicatio n/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
|
|
|

Nov 19 '05 #6
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: <uD************ **@TK2MSFTNGP15 .phx.gbl>
<0A************ *************** *******@microso ft.com>
<za************ **@TK2MSFTNGXA0 1.phx.gbl>
<OW************ **@TK2MSFTNGP14 .phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: st*****@online. microsoft.com (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.publi c.dotnet.framew ork.aspnet
| Message-ID: <YC************ **@TK2MSFTNGXA0 1.phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| Lines: 64
| Path: TK2MSFTNGXA01.p hx.gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1219 77
| NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122
|
| Hi Rob,
|
| Thanks for your response. I'm really feeling strange that the
| "Applicatio n/octet-stream" not work on your product server. The
| "applicatio n/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" <in******@commu nity.nospam>
| | References: <uD************ **@TK2MSFTNGP15 .phx.gbl>
| <0A************ *************** *******@microso ft.com>
| <za************ **@TK2MSFTNGXA0 1.phx.gbl>
| | 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: <OW************ **@TK2MSFTNGP14 .phx.gbl>
| | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| | NNTP-Posting-Host: host217-45-2-106.in-addr.btopenworl d.com 217.45.2.106
| | Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP14.phx. gbl
| | Xref: TK2MSFTNGXA01.p hx.gbl
| microsoft.publi c.dotnet.framew ork.aspnet:1216 50
| | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| |
| | > seems no other particular things except the content-type value.
| Generally,
| | > we can always use the "applicatio n/octet-stream" for all binary data
| |
| | Hi Steven,
| |
| | We originally had "applicatio n/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
| |
| |
| |
|
|

Nov 19 '05 #7
> 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.
Nov 19 '05 #8
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.ClearH eaders();
Response.ClearC ontent();

Response.Conten tType="applicat ion/octet-stream";

Response.AddHea der("content-disposition", "attachment ;
filename=filena me.ext");
Response.WriteF ile(@"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" <in******@commu nity.nospam>
| References: <uD************ **@TK2MSFTNGP15 .phx.gbl>
<0A************ *************** *******@microso ft.com>
<za************ **@TK2MSFTNGXA0 1.phx.gbl>
<OW************ **@TK2MSFTNGP14 .phx.gbl>
<YC************ **@TK2MSFTNGXA0 1.phx.gbl>
<Kk************ **@TK2MSFTNGXA0 1.phx.gbl>
| 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: <ev************ **@tk2msftngp13 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: host217-45-2-106.in-addr.btopenworl d.com 217.45.2.106
| Path:
TK2MSFTNGXA01.p hx.gbl!TK2MSFTF EED02.phx.gbl!t ornado.fastwebn et.it!tiscali!n e
wsfeed1.ip.tisc ali.net!news.ma xwell.syr.edu!c yclone.bc.net!m srtrans!TK2MSFT N
GP08.phx.gbl!tk 2msftngp13.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1228 89
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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.
|
|
|

Nov 19 '05 #9
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

"Steven Cheng[MSFT]" wrote:
Hi Rob,

Thanks for your response. I'm really feeling strange that the
"Applicatio n/octet-stream" not work on your product server. The
"applicatio n/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

Dec 6 '05 #10

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

Similar topics

3
5200
by: svdh2 | last post by:
I have been looking at a problem the entire week in access, I have still not been able to find a solution. Hope that you could maybe tell where to look Concerns the link between Access and Word. I can not transfer a report to word without losing out on the lay-out (RTF format). I understand that there is no way out ok, mail merge I thought. But here I have the problem that I need to merge multiple tables and that I can just include...
4
3368
by: svdh2 | last post by:
Dear All, I have lately strugled more and more with Access, what started as a simple database has brought me to the fundaments of Access. I need to transfer fields from various tables to a word-document to make a decent report (transferring a report from access to word means a lot of loss on lay out, which I find a clear showcase of microsoft's socalled software quality).
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
4693
by: Swe | last post by:
Hi all, I am generated some reports in Word format. While generating them, I have to protect the document from accidental changes...The following is what I have done. object fileNameObj=(Object)stringFileName; object novalue=System.Reflection.Missing.Value; object isVisible = true; object readOnly = false;
3
4885
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)
5
1921
by: Alan T | last post by:
I have created a mail merged document at run time. However, I cannot open the document everytime, sometime it did not get opened, sometimes it can. The document may be Word or text file. public static void OpenDocument(string aFilename) { IntPtr result;
4
2052
by: =?Utf-8?B?S29sbG1vcmdlbg==?= | last post by:
I have an asp page that outputs a word document. Wnen the user attempts to open this page from a hyberlink in an email document the word document opens fine but if they save then an action cancelled message appears in a browser window. If you cut and paste this same link into IE and attempt to saves there is no browser window opened. If the user attempts to open instead of save the document it opens in a word out side the browser. I am...
14
5295
by: Alan T | last post by:
These are the codes I created a document: _WordApp = new Interop.Word.Application(); _WordApp.Visible = false; _WordDoc = new Document(); _Missing = System.Reflection.Missing.Value;
2
1382
by: vipinkmathews | last post by:
I wrote code for previewing a word dcoument in C#. In the code when the user click preview button the document gets opened and later the user manually closes the document. But in Task manager the memory is not reducing. Actually after opening the document i'm not closing the Word Document instance or not Quitting the Word instance because the user wants the word document to be opned. But in finally block i'm making the word dcoument, word...
0
8707
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
9174
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...
0
9015
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7953
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
5947
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4464
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4725
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3158
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
2
2520
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.