954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to download a file through dropdownlist using asp.net

Hi

Can any one tell my how can i download a file from MySql through dropdownlist

What i'm trying to do is i created a dropdownlist and shows all the file name in that dropdownlist now i want user to be able to download that file when they select any item on the list. Once they click on any item on the list it should popup a download window that they can click on SaveAs button to download that file.

I have saved only a link in the database and the actual file is saved in a folder i created

please help!!

thanks.

Aviplo
Light Poster
36 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

This is straight coding, enable the dropdown list autopostback property true, capture its onselectedindex change event. if you save the file name and path in db, your dropdown value should be "Path" and text should be "file name". And to download the file see following link:

http://stackoverflow.com/questions/5596747/download-stream-file-from-url-asp-net

Or google more, you will find plenty of links.

sufyan2011
Junior Poster
166 posts since Dec 2011
Reputation Points: 9
Solved Threads: 20
 

Thank you sufyan2011 for helping me. It really helped :D

Aviplo
Light Poster
36 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

hey i tried this one

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

Response.Redirect("../meeting/"+ DropDownList1.SelectedItem.Value );


}

the i click on any filename to download and it did work but only just the first time only. The second time i try to click on the other file but this error was shown

Forbidden
You do not have permission to access this document.

what should i do?

thanks.

Aviplo
Light Poster
36 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

now i have a problem with the dropdownlist selectedindexchanged event is fire only the 0th index no mather in what index i clicked on
so here comes the code

private void loadData()
{

DataTable DT = new DataTable();
OdbcCommand cmd;
OdbcConnection conn = new OdbcConnection(constr);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
OdbcCommand sql = new OdbcCommand("SET CHARACTER SET `tis620`", conn);
sql.ExecuteNonQuery();
sql.Dispose();
}

cmd = new OdbcCommand("SELECT ifnull( filename, '' ) AS filename,name FROM `abt_meeting_topic` left join abt_meeting on abt_meeting.aid = abt_meeting_topic.id ", conn);

try
{
OdbcDataReader dReader = cmd.ExecuteReader();

{
DropDownList1.DataSource = dReader;
DropDownList1.DataTextField = "name";
DropDownList1.DataValueField = "filename";
DropDownList1.DataBind();
dReader.Close();

}
}
catch (Exception ex)
{
Response.Write(Utility.MessageBox("ไม่สามารถเรียกข้อมูลได้ กรุณาแจ้งผู้ดูแลระบบ (Error : " + ex + ")"));
}
if (conn.State == ConnectionState.Open)
{ conn.Close(); conn.Dispose(); }
}


protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

Response.Write("../meeting/" + DropDownList1.SelectedItem.Text);

}

every comment appreciated.

Aviplo
Light Poster
36 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

* Correct the above code

Actually I used Response.Redirect instead of Response.Write


protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

Response.Redirect("../meeting/" + DropDownList1.SelectedItem.Text);

}

Aviplo
Light Poster
36 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You