im currently working on project doing file management, and i just finish the code for upload file into my database(.mdf) table, however i have no idea how to download the file back to my folder(or anywhere else). I see people do download from ASP.Net, OR web sql database, but i wish if someone could tell me how to download it from a mdf database.
private void find_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
string Path = dlg.FileName.ToString();
PathBox.Text = Path;
PicBox.location = Path;
}
}
private void save_Click(object sender, eventargs e)
{
byte[] Doc = null;
Filestream fs = new FileStream(this.PathBox.Text, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
Doc = br.ReadBytes((int)fs.Length);
string DS = "datasource = localDB ......";
string Insertcmd = "insert into ......";
MySqlConnection conn = new MySqlConnection(DS);
MySqlCommand cmd = new MySqlCommand(Insertcmd, conn);
MySqlDataReader msdr;
try
{
conn.Open();
cmd.Parameter.Add(new MySqlParameter("@Document", Doc));
msdr = cmd.ExecuteReader();
MessageBox.Show("file saved");
While (msdr.Read())
{
}
catch (Exception ex)
{
}
}
could someone give me a code that is able to download from .mdf database? or even any hint will be very helpful
thanks
HI It seems that you are saving the file in a binary format (BLOB ) object ? So when you want to show the image after getting from Database you could read it using a memory stream and show it. or maybe use context.Response.BinaryWrite() to output the image.
http://csharpdotnetfreak.blogspot.com/2009/07/display-images-gridview-from-database.html might be helpful.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.