Control Panel
Forum
Hosting Help
6 Months free Hosting (New!)
Resources
Login
Members
Shared Hosting
|
New Features
|
Advertise
|
Tutorials
|
Product Reviews in India
|
Free aptitude test questions
|
TATA Nano Car reviews
Total
members
:
76939
Average new registrations per day (in last 7 days):
82
New Registration:
Open
Register Now
Home
»
Questions & Answers
»
DOWNLOAD BUTTON CODE IN C#
DOWNLOAD BUTTON CODE IN C#
3/28/2008
Author:
Ashutosh Gupta
Jabalpur Engg. College
http://aspspider.info/Ashutoshgupta
MYWEBSITE
please tell me hoiw to code for a simple download button in asp.net c#. kindly explain if possible.
thanx in advance.
Answers .............
Author:
Timothy Parez
Techdeta
Posted Date: 3/28/2008
http://aspspider.info/timothyp
codem
Hello,
Can you explain in more detail what you are trying to accomplish ?
Do you simply want a button to link to a file ?
For example
<asp:Button id="btnDownload" runat="server" OnClick="btnDownload_Click"/>
public void btnDownload_Click(object source, EventArgs e)
{
Response.Redirect("url_to_the_file_you_want");
}
Or did you have something else in mind?
Author:
Rod Tidwell
Posted Date: 3/29/2008
http://aspspider.biz/antartica
Antartica
Hi,
If I understand it right, you want to download a file (not open it) when you click a button. Check this out:
---------------------------------------------------------
string URL = @"
FileInfo" target=_blank>http://.../myFileToDownload.txt";
FileInfo
fileInfo = new FileInfo(URL);
if (fileInfo.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Flush();
Response.WriteFile(fileInfo.FullName);
}
---------------------------------------------------------
Author:
Rod Tidwell
Posted Date: 3/29/2008
http://aspspider.biz/antartica
Antartica
Sorry, the previous message has been screwed up (weird forum...):
---------------------------------------------------------
string URL = "your_url";
FileInfo fileInfo = new FileInfo(URL);
if (fileInfo.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Flush();
Response.WriteFile(fileInfo.FullName);
}
---------------------------------------------------------
Author:
Ashutosh Gupta
Jabalpur Engg. College
Posted Date: 3/29/2008
http://aspspider.info/Ashutoshgupta
MYWEBSITE
This is absolutely what i wanted........
Thanx to u all.
response.redirect("file"); Doesn't work for wierd file types. I wanted the file to be downloaded and not open up in browser. Thanx for u r support.
Author:
Asif Mahmood
Posted Date: 3/29/2008
http://aspspider.net/flare
Asif's Home Page
for this may u hav to chack the allowed meta types ono ur hosting...i think so...
Author:
Ashutosh Gupta
Jabalpur Engg. College
Posted Date: 3/30/2008
http://aspspider.info/Ashutoshgupta
MYWEBSITE
what do i need to import for using FILEINFO class ?
Author:
Ashutosh Gupta
Jabalpur Engg. College
Posted Date: 3/30/2008
http://aspspider.info/Ashutoshgupta
MYWEBSITE
I found it :
System.IO.FileInfo .....
Author:
Ashutosh Gupta
Jabalpur Engg. College
Posted Date: 3/30/2008
http://aspspider.info/Ashutoshgupta
MYWEBSITE
The code is still not working .........
actually i want that when a person clicks on the button...
the browser shud open a "download dialog box".
Author:
Rod Tidwell
Posted Date: 3/30/2008
http://aspspider.biz/antartica
Antartica
Is my first piece of code working? For me, it works, even with weird files extension (.smx and .scx). Did you try it out?
Author:
Haider Raza
Integral University
Posted Date: 4/1/2008
can u clear ur question plzzzzzz
Author:
Ashutosh Gupta
Jabalpur Engg. College
Posted Date: 4/1/2008
http://aspspider.info/Ashutoshgupta
MYWEBSITE
first of all i want to tell u all that i am just a beginner...
This is a link to mywebsite :
http:\\aspspider.info\Ashutoshgupta
here u can see a download Link button reading "download my resume".
i have uploaded the file on server.
I want that when a user clicks on it, the save file dialog of the browser shud open and ask for save location .
IS IT CLEAR NOW ?
Author:
3CP12
octo
Posted Date: 4/1/2008
http://aspspider.info/octopus
...
Author:
Rod Tidwell
Posted Date: 4/1/2008
http://aspspider.biz/antartica
Antartica
---------------------------------------------------------
string URL = "your_url";
FileInfo fileInfo = new FileInfo(URL);
if (fileInfo.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Flush();
Response.WriteFile(fileInfo.FullName);
}
---------------------------------------------------------
Author:
Ashutosh Gupta
Jabalpur Engg. College
Posted Date: 4/2/2008
http://aspspider.info/Ashutoshgupta
MYWEBSITE
what is to be written inside the tag of button's onClick ??
<asp:Button ID="Button1" runat="server" Text="download "
OnClick=Button1_click(?? , ??)/>
Author:
Ashutosh Gupta
Jabalpur Engg. College
Posted Date: 4/2/2008
http://aspspider.info/Ashutoshgupta
MYWEBSITE
Thanx to all........
i have accomplished what i wanted to do......
Author:
Abdullah Kamran
Free Spirit Services Limited
Posted Date: 4/2/2008
http://aspspider.info/akamrans
Free Spirit Services Limited
This was what I wanted as well ... many thanks
Author:
Ensonn Ting
Posted Date: 4/2/2008
http://aspspider.info/xiaoxiang85
Forum
ok...downloaded......hehe.....
Author:
ngo xuan dang
gas
Posted Date: 4/2/2008
http://aspspider.info/ngoxuandang
An toàn Môi tru?ng
Thanx to all
i have accomplished
You must
login
to post answer for this question.
Partners
Privacy Policy
Terms of use
Contact Us
SpiderWorks Technologies.
All Rights Reserved.