Is there a way to have the server send a file to client (ie download) from a
button click and a filename string? 11 1619
"John Smith Jr." <me@isp.com> wrote in message
news:ON******** ******@TK2MSFTN GP12.phx.gbl... Is there a way to have the server send a file to client (ie download) from
a button click and a filename string?
Yes. And it can even be done with client side code if you want, using an
<input type="button"
onclick="javasc ript:window.loc ation.href='MyD ownload.pdf' /> type of form
element.
if you want to stream it on the server, you can open a FileStream and post
the resulting binary data to the Response.Output Stream
R.
Hi John,
If you want a server-side method, try this?
Private Sub LinkButton1_Cli ck _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) _
Handles LinkButton1.Cli ck
Dim FilePath As String = "C:\downloads\s etup.exe"
Dim FileName As String = "setup.exe"
'Set the appropriate ContentType.
Response.Conten tType = "applicatio n/octet-stream"
Response.AddHea der("Content-Disposition", _
"attachment ; filename=" & FileName)
'Write the file directly to the HTTP output stream.
Response.WriteF ile(FilePath)
Response.End()
End Sub
<form id="Form1" method="post" runat="server">
<asp:LinkButt on id="LinkButton1 " runat="server"> Click to
download</asp:LinkButton>
</form>
"John Smith Jr." <me@isp.com> wrote in message
news:ON******** ******@TK2MSFTN GP12.phx.gbl... Is there a way to have the server send a file to client (ie download) from
a button click and a filename string?
That worked great!
Thank you much.
Had to convert it to C#, but thats pretty easy.
A few questions though, there is a pause before it starts downloading, which
isn't to long but it is local lan, not a big deal though. But it seems to
use "default" as a file name, is there anyway to set what the destination
file name should be by default?
"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message
news:eO******** ******@TK2MSFTN GP12.phx.gbl... Hi John,
If you want a server-side method, try this?
Private Sub LinkButton1_Cli ck _ (ByVal sender As System.Object, _ ByVal e As System.EventArg s) _ Handles LinkButton1.Cli ck Dim FilePath As String = "C:\downloads\s etup.exe" Dim FileName As String = "setup.exe" 'Set the appropriate ContentType. Response.Conten tType = "applicatio n/octet-stream" Response.AddHea der("Content-Disposition", _ "attachment ; filename=" & FileName) 'Write the file directly to the HTTP output stream. Response.WriteF ile(FilePath) Response.End() End Sub
<form id="Form1" method="post" runat="server"> <asp:LinkButt on id="LinkButton1 " runat="server"> Click to download</asp:LinkButton> </form>
"John Smith Jr." <me@isp.com> wrote in message news:ON******** ******@TK2MSFTN GP12.phx.gbl... Is there a way to have the server send a file to client (ie download)
from a button click and a filename string?
Hi John,
It should be using whatever name you supply the FileName variable, which in
my code is "setup.exe" . Not sure how Default enters it, unless it is picking
that up from the name of your .aspx page.
As for the speed, it should be quite fast unless something is taking time to
compile or check permissions.
Ken
"John Smith Jr." <me@isp.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. .. That worked great! Thank you much.
Had to convert it to C#, but thats pretty easy.
A few questions though, there is a pause before it starts downloading,
which isn't to long but it is local lan, not a big deal though. But it seems to use "default" as a file name, is there anyway to set what the destination file name should be by default?
"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message news:eO******** ******@TK2MSFTN GP12.phx.gbl... Hi John,
If you want a server-side method, try this?
Private Sub LinkButton1_Cli ck _ (ByVal sender As System.Object, _ ByVal e As System.EventArg s) _ Handles LinkButton1.Cli ck Dim FilePath As String = "C:\downloads\s etup.exe" Dim FileName As String = "setup.exe" 'Set the appropriate ContentType. Response.Conten tType = "applicatio n/octet-stream" Response.AddHea der("Content-Disposition", _ "attachment ; filename=" & FileName) 'Write the file directly to the HTTP output stream. Response.WriteF ile(FilePath) Response.End() End Sub
<form id="Form1" method="post" runat="server"> <asp:LinkButt on id="LinkButton1 " runat="server"> Click to download</asp:LinkButton> </form>
"John Smith Jr." <me@isp.com> wrote in message news:ON******** ******@TK2MSFTN GP12.phx.gbl... Is there a way to have the server send a file to client (ie download) from a button click and a filename string?
I tried changing the name of the form to default2, and the default file name
changed to default2.
Also, when it shows save as dialog, the file type is blank, i assume this is
because it saves it as "default2" without an extension. But if there was a
way to change this default filename, it would be great.
"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. .. Hi John,
It should be using whatever name you supply the FileName variable, which
in my code is "setup.exe" . Not sure how Default enters it, unless it is
picking that up from the name of your .aspx page.
As for the speed, it should be quite fast unless something is taking time
to compile or check permissions.
Ken
"John Smith Jr." <me@isp.com> wrote in message news:%2******** ********@tk2msf tngp13.phx.gbl. .. That worked great! Thank you much.
Had to convert it to C#, but thats pretty easy.
A few questions though, there is a pause before it starts downloading, which isn't to long but it is local lan, not a big deal though. But it seems
to use "default" as a file name, is there anyway to set what the
destination file name should be by default?
"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message news:eO******** ******@TK2MSFTN GP12.phx.gbl... Hi John,
If you want a server-side method, try this?
Private Sub LinkButton1_Cli ck _ (ByVal sender As System.Object, _ ByVal e As System.EventArg s) _ Handles LinkButton1.Cli ck Dim FilePath As String = "C:\downloads\s etup.exe" Dim FileName As String = "setup.exe" 'Set the appropriate ContentType. Response.Conten tType = "applicatio n/octet-stream" Response.AddHea der("Content-Disposition", _ "attachment ; filename=" & FileName) 'Write the file directly to the HTTP output stream. Response.WriteF ile(FilePath) Response.End() End Sub
<form id="Form1" method="post" runat="server"> <asp:LinkButt on id="LinkButton1 " runat="server"> Click to download</asp:LinkButton> </form>
"John Smith Jr." <me@isp.com> wrote in message news:ON******** ******@TK2MSFTN GP12.phx.gbl... > Is there a way to have the server send a file to client (ie
download) from a > button click and a filename string? > >
Perhaps you could show us the code so we can demonstrate how it should work?
"John Smith Jr." <me@isp.com> wrote in message
news:eB******** *****@tk2msftng p13.phx.gbl... I tried changing the name of the form to default2, and the default file
name changed to default2.
Also, when it shows save as dialog, the file type is blank, i assume this
is because it saves it as "default2" without an extension. But if there was
a way to change this default filename, it would be great.
This is the method i am using and it uses the name of the form for the
default filename:
private void downloadFileBut ton_Click (object sender, System.EventArg s e)
{
Button myButton;
myButton = (Button)sender;
// pass through the filename from the table row
// TODO: convert to viewstate for security
string filename = myButton.Attrib utes["file"].ToString();
// set http headers and content type
Response.Conten tType = "applicatio n/octet-stream";
Response.AddHea der("Content-Disposition", "Attachment ; filename=" +
filename);
// send file
Response.WriteF ile(filename);
// disconnect
Response.End();
}
"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message
news:eM******** ******@TK2MSFTN GP10.phx.gbl... Perhaps you could show us the code so we can demonstrate how it should
work? "John Smith Jr." <me@isp.com> wrote in message news:eB******** *****@tk2msftng p13.phx.gbl... I tried changing the name of the form to default2, and the default file name changed to default2.
Also, when it shows save as dialog, the file type is blank, i assume
this is because it saves it as "default2" without an extension. But if there
was a way to change this default filename, it would be great.
Hi John,
Your problem was here near the end:
Response.WriteF ile(filepath);
That's where you supply the physical file that you are sending. Filename is
just the friendly/default name to show in the browser.
private void downloadFileBut ton_Click (object sender, System.EventArg s e)
{
Button myButton;
myButton = (Button)sender;
// pass through the filename from the table row
// TODO: convert to viewstate for security
//string filename = myButton.Attrib utes["file"].ToString();
string filename = myButton.Comman dArgument;
string filepath = "c:\\temp\\setu p.exe";
// set http headers and content type
Response.ClearC ontent();
Response.ClearH eaders();
Response.Conten tType = "applicatio n/octet-stream";
Response.AddHea der("Content-Disposition", "attachment;fil ename=" +
filename.ToStri ng());
// TODO: John: Remember that the filepath and filename are two
// different issues. One is for your program to find the file
// the other is to give to give a friendly default name for the download
// send file
// Change this to the physical file name you want to send
Response.WriteF ile(filepath);
// disconnect
Response.End();
}
"John Smith Jr." <me@isp.com> wrote in message
news:ON******** ******@TK2MSFTN GP12.phx.gbl... This is the method i am using and it uses the name of the form for the default filename:
private void downloadFileBut ton_Click (object sender, System.EventArg s
e) { Button myButton; myButton = (Button)sender;
// pass through the filename from the table row // TODO: convert to viewstate for security string filename = myButton.Attrib utes["file"].ToString();
// set http headers and content type Response.Conten tType = "applicatio n/octet-stream"; Response.AddHea der("Content-Disposition", "Attachment ; filename=" + filename);
// send file Response.WriteF ile(filename);
// disconnect Response.End(); }
"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message news:eM******** ******@TK2MSFTN GP10.phx.gbl... Perhaps you could show us the code so we can demonstrate how it should work? "John Smith Jr." <me@isp.com> wrote in message news:eB******** *****@tk2msftng p13.phx.gbl... I tried changing the name of the form to default2, and the default
file name changed to default2.
Also, when it shows save as dialog, the file type is blank, i assume
this is because it saves it as "default2" without an extension. But if there was a way to change this default filename, it would be great.
That worked great, thank you much Ken.
Great help.
"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message
news:ej******** ******@TK2MSFTN GP12.phx.gbl... Hi John,
Your problem was here near the end:
Response.WriteF ile(filepath);
That's where you supply the physical file that you are sending. Filename
is just the friendly/default name to show in the browser.
private void downloadFileBut ton_Click (object sender, System.EventArg s
e) { Button myButton; myButton = (Button)sender;
// pass through the filename from the table row // TODO: convert to viewstate for security //string filename = myButton.Attrib utes["file"].ToString(); string filename = myButton.Comman dArgument; string filepath = "c:\\temp\\setu p.exe"; // set http headers and content type Response.ClearC ontent(); Response.ClearH eaders(); Response.Conten tType = "applicatio n/octet-stream"; Response.AddHea der("Content-Disposition", "attachment;fil ename=" + filename.ToStri ng()); // TODO: John: Remember that the filepath and filename are two // different issues. One is for your program to find the file // the other is to give to give a friendly default name for the
download // send file // Change this to the physical file name you want to send Response.WriteF ile(filepath);
// disconnect Response.End(); }
"John Smith Jr." <me@isp.com> wrote in message news:ON******** ******@TK2MSFTN GP12.phx.gbl... This is the method i am using and it uses the name of the form for the default filename:
private void downloadFileBut ton_Click (object sender, System.EventArg s e) { Button myButton; myButton = (Button)sender;
// pass through the filename from the table row // TODO: convert to viewstate for security string filename = myButton.Attrib utes["file"].ToString();
// set http headers and content type Response.Conten tType = "applicatio n/octet-stream"; Response.AddHea der("Content-Disposition", "Attachment ; filename=" + filename);
// send file Response.WriteF ile(filename);
// disconnect Response.End(); }
"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message news:eM******** ******@TK2MSFTN GP10.phx.gbl... Perhaps you could show us the code so we can demonstrate how it should work? "John Smith Jr." <me@isp.com> wrote in message news:eB******** *****@tk2msftng p13.phx.gbl... > I tried changing the name of the form to default2, and the default file name > changed to default2. > > Also, when it shows save as dialog, the file type is blank, i assume
this is > because it saves it as "default2" without an extension. But if
there was a > way to change this default filename, it would be great. >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jim Bayers |
last post by:
Currently, users click on a button to download data. They click and wait
patiently for a minute for the sql server to send them their data. Problem
is, some users keep clicking on the button over and over.
What I would like to do is that when users click on the button, they are
taken to another page that has 'please wait a moment...' and...
|
by: jmd |
last post by:
Hello.
I want to write a C# program that does completely automatically what, until
now, I do manually, witch is describe below :
1. I launch IE (6)
2. I browse to my desired download page, say
http://www.site.com/download
This download page contains some textboxes, checkboxes,
radiobuttons, a DOWNLOAD BUTTON and text
3. I check some...
|
by: Dave |
last post by:
Hi all,
Apologies if this is the wrong group. I have done a
search on google but my keywords are probably no good.
What I want to do is to display a list of data in a
datagrid (which I have already done). At the side of the
list, I want to put in a checkbox, basically to select
that line.
|
by: aarondouglas28 |
last post by:
Hey all,
I'm hoping someone can help me with a problem I'm having. I have a page
that has a javascript based slide show of images on it. The user can
press a play button and the page will cycle through all of the images
that match a certain criteria. At any point, the user can press the
stop button to stop the slide show.
What I need is a...
|
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...
| |
by: Ken Varn |
last post by:
I have an ASP.NET page that incorporates the following code on a button
press.
private void DownloadTag_Command(object sender, CommandEventArgs e)
{
FileStream fs;
String Filename;
Filename = MapPath(e.CommandArgument as string); // Name of file
is passed in cmd arg.
|
by: jmd |
last post by:
Hello, I posted the following in the C# forum but without one answer.
But perhaps now in vb.net someone has some guidelines !
This is my question :
I want to write a vb.net program that does completely automatically what,
until
now, I do manually, witch is describe below :
1. I launch IE (6)
|
by: comp.lang.php |
last post by:
I have a form that when you click the "Generate Report" submit button,
it will force download a CSV file, required for this project.
On the very same page you also have a "Search" submit button, when you
press it it should generate search results in a new page.
However, when you click the "Generate Report" submit button, the moment
you...
|
by: msxkim |
last post by:
My web app writes some binary data to a file at the client site via
Response.BinaryWrite. This action is accomplished
in response to a button click, with C# code behind as follows:
private void SubmitButton_Click (object sender, System.EventArgs e)
{
// Set up the response to write the print file to the client
Response.Clear ();...
|
by: rohit3291 |
last post by:
Friends i need your help on the below issue please help me urgent......
Thanks in advance...
I have a web site where i have a button called report. On click of report button some data is being written in to a html file and a new window appears as expected.Here in this new window i have two frames.In the first frame i am displaying the html...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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.
| |