My web app writes some binary data to a file at the client site via
Response.Binary Write. This action is accomplished
in response to a button click, with C# code behind as follows:
private void SubmitButton_Cl ick (object sender, System.EventArg s e)
{
// Set up the response to write the print file to the client
Response.Clear ();
Response.Buffer =false;
Response.Append Header ("Content-Disposition",
"filename=WebPr int.prn");
Response.Append Header ("Content-Length", filename.length .ToString
());
Response.Conten tType = "applicatio n/octet-stream";
Response.Binary Write (buf); // Write binary data
Response.Flush( );
Response.End ();
}
This works fine for first time. User sees a File Save As dialog box
and download a file to the local drive. But my problem is that when
user clicks 'Download' button again, the browser is filled with junk
funny characters. If I close the browser after the download and open
it again then click download button, it works always. Most of time, I
get this behavior when I click download button for the second time,
sometimes third click.
Please help. 2 2173
See inline
My web app writes some binary data to a file at the client site via
Response.Binary Write. This action is accomplished
in response to a button click, with C# code behind as follows:
private void SubmitButton_Cl ick (object sender, System.EventArg s e)
{
// Set up the response to write the print file to the client
Response.Clear ();
Response.Buffer =false;
Response.Append Header ("Content-Disposition",
"filename=WebPr int.prn");
Change the line above to:
Response.Append Header ("Content-Disposition",
"attachment;fil ename=WebPrint. prn");
Response.Append Header ("Content-Length", filename.length .ToString
());
Response.Conten tType = "applicatio n/octet-stream";
Response.Binary Write (buf); // Write binary data
Response.Flush( );
Response.End ();
}
This works fine for first time. User sees a File Save As dialog box
and download a file to the local drive. But my problem is that when
user clicks 'Download' button again, the browser is filled with junk
funny characters. If I close the browser after the download and open
it again then click download button, it works always. Most of time, I
get this behavior when I click download button for the second time,
sometimes third click.
Please help.
Hans,
Thanks for your reply,
I did changed AppendHeader line and tried.
But I got the same result. In this time, I was able to click download
button 4 time before my browser is filled with funny characters. I am
trying many different ways to download files.
Context.Respons e.Clear();
Context.Respons e.ContentType = "applicatio n/octet-stream";
Context.Respons e.AppendHeader( "Content-Disposition", "attachment ;
filename=" + pstrFileName);
Context.Respons e.AppendHeader( "Content-Length",
objStream.Lengt h.ToString());
Context.Respons e.Buffer=false;
byte[] buffer = new byte[m_bufferSize];
long byteCount;
try
{
while ((byteCount = objStream.Read( buffer, 0, buffer.Length)) 0)
{
if(Context.Resp onse.IsClientCo nnected)
{
Context.Respons e.OutputStream. Write(buffer, 0, buffer.Length);
Context.Respons e.Flush();
}
else
{
OnDownloadCance lled();
return;
}
}
OnDownloadCompl eted();
}
catch(Exception ex)
{
throw ex;
}
finally
{
objStream.Close ();
Context.Respons e.End();
}
Hans Kesting wrote:
See inline
My web app writes some binary data to a file at the client site via
Response.Binary Write. This action is accomplished
in response to a button click, with C# code behind as follows:
private void SubmitButton_Cl ick (object sender, System.EventArg s e)
{
// Set up the response to write the print file to the client
Response.Clear ();
Response.Buffer =false;
Response.Append Header ("Content-Disposition",
"filename=WebPr int.prn");
Change the line above to:
Response.Append Header ("Content-Disposition",
"attachment;fil ename=WebPrint. prn");
Response.Append Header ("Content-Length", filename.length .ToString
());
Response.Conten tType = "applicatio n/octet-stream";
Response.Binary Write (buf); // Write binary data
Response.Flush( );
Response.End ();
}
This works fine for first time. User sees a File Save As dialog box
and download a file to the local drive. But my problem is that when
user clicks 'Download' button again, the browser is filled with junk
funny characters. If I close the browser after the download and open
it again then click download button, it works always. Most of time, I
get this behavior when I click download button for the second time,
sometimes third click.
Please help.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: aa |
last post by:
Is it OK to include an ANSI file into a UTF-8 file?
|
by: Lokkju |
last post by:
I am pretty much lost here - I am trying to create a managed c++
wrapper for this dll, so that I can use it from c#/vb.net, however, it
does not conform to any standard style of coding I have seen. It is
almost like it is trying to implement it's own COM interfaces...
below is the header, and a link to the dll+code:
Zip file with header, example, and DLL:...
|
by: Norton |
last post by:
Hi all,
I would like to know if there is any method in asp or asp.net to direct the
browser to download a file into the Temporary Internet Files directory so
that i can make use of vb script to do the further process
ie. tells IE to download my desired Word File into the Temporary Internet
Files and call an office com object to open it
|
by: Daniel Cardoso |
last post by:
I don't know what else to try - In my asp.net app, when the file name has
Windows-1252 characters (like ã and ç), these characters appear, each one,
as two strange characters in the file name label in Internet Explorer File
Download Dialog that is shown when I click a link to download the file. The
file content is being generated on-the-fly using asp.net and the filename is
being passed using a call to Response.AddHeader with the strings...
|
by: Nathan Sokalski |
last post by:
I want to give visitors to my site the option of downloading a generated
..txt file by clicking a button. I know how to generate text files, but how
do I cause the browser to pop up one of those dialog boxes that says
something like "Do you want to download FILEX.txt?" I want the user to be
able to download the file rather than have the file displayed in the
browser, because the file will include some characters such as tabs and
commas....
| |
by: devospice |
last post by:
Hi,
I'm trying to create a download counter for individual files on a web
site and I'm not sure how to do this. Right now I'm using Webalizer
to just read the log files and see how many times the files I'm
interested in were downloaded. The problem is Webalizer breaks it up
by month and I want a running total. I'd also like to see the counts
without having to log in to Webalizer in the first place. Not that
logging in or adding the...
|
by: lawrence k |
last post by:
I've got a music studio for a client. Their whole studio is run with
Macintosh computers. Macintosh computers allow file names to have open
white spaces, such as "animal hospital.mp3".
I have a download script, so customers on the website can download
MP3s to their harddrive (rather than merely listen to it in their
browsers):
|
by: efrenba |
last post by:
Hi,
I came from delphi world and now I'm doing my first steps in C++. I'm
using C++builder because its ide is like delphi although I'm trying to
avoid the vcl.
I need to insert new features to an old program that I wrote in delphi
and it's a good opportunity to start with c++.
|
by: KevinADC |
last post by:
Note: You may skip to the end of the article if all you want is the perl code.
Introduction
Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script.
What You Need
Any recent...
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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: 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...
|
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: 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();...
|
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.
| | |