0

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.

2
Contributors
5
Replies
8
Views
5 Years
Discussion Span
Last Post by Aviplo
0

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

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.

Edited by Dani: Formatting fixed

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.

Edited by Dani: Formatting fixed

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);

        }

Edited by Dani: Formatting fixed

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.