I have a downloader page in my asp.net application that looks at a
session variable to get the path to the file, checks it then downloads
it using the Response object. When the "File Download" dialog comes up,
if the user clicks "Save" and then opens the file, it works great. If
the user clicks save and then opens the document up from their local
computer it always (100%) works fine. However, if they choose "Open"
instead then most of the time (90%) the right application launches on
the users computer, but then fails opening the document. Most of the
office applications report back that the file could not be found, and
shows the path to the file in the Contents of the IE directory
structure. However, Adobe Acrobat just reports that the document could
not be opened.
Here's my code for the downloader:
<code>
string path = Session["filedownloadpa th"].ToString();
if(File.Exists( path))
{
FileInfo fi = new FileInfo(path);
Response.Clear( );
Response.Buffer = false;
switch(fi.Exten sion)
{
case ".pdf":
// Response.Conten tType = "applicatio n/pdf";
break;
default:
// Response.Conten tType = "applicatio n/octet-stream";
break;
}
string name = Path.GetFileNam e(path);
Response.Conten tType = "applicatio n/x-msdownload";
Response.AddHea der("Content-Disposition","a ttachment;filen ame= "
+ fi.Name);
Response.AddHea der("Content-Length", fi.Length.ToStr ing());
Response.Flush( );
FileStream iStream = new FileStream(path ,
System.IO.FileM ode.Open,
FileAccess.Read ,
FileShare.Read) ;
byte[] buffer = new byte[10000];
int length = 0;
long datatoread = 0;
datatoread = iStream.Length;
while(datatorea d>0)
{
if(Response.IsC lientConnected)
{
length = iStream.Read(bu ffer, 0, 10000);
Response.Output Stream.Write(bu ffer, 0, length);
Response.Flush( );
buffer = new byte[10000];
datatoread = datatoread - length;
}
else
{
datatoread = -1;
}
}
iStream.Close() ;
//Response.WriteF ile(path);
Response.End();
}
else
{
throw new Exception("File Not Found");
}
</code>
I have tried this in Firefox and it works fine. Any suggestions? Anyone
else run into this lately? 0 1756 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: AlexB |
last post by:
I'm trying to download a text file to an IE client using
the following code. The problem is that the saved file
also includes the html for the page.
Any ideas anyone?
Private Sub Button5_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button5.Click
|
by: Edwin Knoppert |
last post by:
I have not much good response lately on the ASP.NET website, so i'll try it
here.
I have a problem with downloading a PDF by using the response object.
A part of it:
..Response.Clear()
..Response.ContentType = sFileType
..Response.AppendHeader("Content-Disposition", "attachment; filename=" &
sFileNameOut)
|
by: Tony K |
last post by:
I have the most peculiar problem with an ASP.NET page which we use for
downloading a file.
When the user clicks on a link, the link points to an ASPX page which
downloads the file selected.
The code works fine except after the user saves the file, the links on the
left side of the
frameset do not work. IE locks up.
|
by: moondaddy |
last post by:
Using vb.net I need to download image files to the client browser where they
can save to disk. Below is some sample code I'm using. when I run this the
File Download window in the browser says:
File name: ViewAttachment
File type:
From localhost
1) "ViewAttachment" is the name of the aspx page and not the image file.
2) Its not picking up the file type of jpg. For ContentType I used
|
by: Amol Guttal via .NET 247 |
last post by:
(Type your message here)
--------------------------------
From: Amol Guttal
Hi,
This is the code which used to download a file from webserver.
If I point a file in my localhost for download it is working fine but when I point to a file in a remote server it is downloading the file but is corrupted and can't be open.
Please reply back soooooon.
Response.Clear();
| |
by: theyas |
last post by:
How can I get my code to NOT display two "Open/Save/Cancel/More Info" dialog boxes when using the "Response.WriteFile" method to download a file to IE
I've asked about this before and didn't get a satisfactory answer (check your browser) so now that I've had the time to set up a reasonable little test that I can post somewhere, I'll try again.
The app I've written has three ASPX pages. One is a combined page which writes a little text...
|
by: Edwin Knoppert |
last post by:
I have a problem with downloading a PDF by using the response object.
A part of it:
..Response.Clear()
..Response.ContentType = sFileType
..Response.AppendHeader("Content-Disposition", "attachment; filename=" &
sFileNameOut)
..Response.AppendHeader("Content-Length", fs.Length.ToString)
..Response.AppendHeader("Content-Transfer-Encoding", "BINARY")
..Response.Flush()
|
by: Bala |
last post by:
Hi
I am trying to download the PDF files from my webserver using ASP.Net.
All my files are stored at F Drive on webserver. Like this F:\Main
Folder\Sub Folder\Files\File1.pdf
I am impersonating the domain user account and downloading the file, It
seems the impersonate is got success, but its not download the file. Its
simply downloading some junk pdf file instead of original file.
|
by: Adela Arpitha |
last post by:
hi Frinny hope u'll notice my new doubt.
how is this downloading option given in asp.net? im using asp.net 1.1 n c# as programming lang and sql server as back end.
i actually tried it worked fine but only for a single file, in case if i give more than i file for download in the same page it gives the first file only for download it isnt considering the second one ....
private void Page_Load(object sender, System.EventArgs e)
{...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |