Hello
I want to download a file what i have previously uploaded.
I have an asp.net application that contain.
One textbox for id and one fileupload control for upload document and one button for upload document and also i take one folder name Upload in my website
I am created a database
Eid integer primary key
EFilename nvarchar(100)
Then i write coding for upload the file in button_click.
using System.Data.SqlClient
SqlConnection con;
con = new SqlConnection("Server=DELL\\SQLEXPRESS;database=Student;integrated security=true");
con.Open();
string ph = "~/Upload/" + FileUpload1.FileName;
FileUpload1.SaveAs(MapPath(ph));
string str = "insert into upload values('" + TextBox1.Text + "','" + ph + "')";
SqlCommand cmd = new SqlCommand(str, con);
cmd.ExecuteNonQuery();
Response.Write("Value inserted");
con.Close();
Then the path of file will be stored in data base.and physical file will be stored in Upload folder
Now i want download a file what i have uploaded into database.
for that
i have taken another webfrom on that website that web form contain one dropdownlist for select file what u want to download
and also bind with database with dropdownlist and i have take one button also for downloading
i have write following a code in button_click for downloading
string fname = DropDownList1.SelectedItem.Text;
string filepath = Server.MapPath(@"~\Upload\" + fname);
FileInfo fi = new FileInfo(filepath);
if (fi.Exists )
{
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment;filename=" + fname);
Response.AddHeader("Content-Length", fi.Length.ToString());
Response.ContentType = "application";
Response.TransmitFile(fi.FullName);
Response.End();
}
it's working only for dropdpwnlist item[0] element can only downloaded
but not working for remaining items in dropdownlist
when i selcted the dropdownlist item[1] then the item[0] only downloaded
so what i can do
send me u suggestion
Regrds
Reshma