如何将图像从sql数据库保存到文件夹中

问题描述:

如何从sql database中将Image保存到文件夹(Server.MapPath(Temp\\))。

How to save Image into folder(Server.MapPath("Temp\\" )) from sql database.

图像保存在数据库中后,您可以检索图像并保存在文件中,如下所示:



Once the image is saved in the database, you can retreive the image and save in a file as follows:

SqlCommand mycmd = new SqlCommand("select image_field from your_table where field_id = @ID",yourSqlConn);
cmdSelect.Parameters.Add("@ID",SqlDbType.Int,4);
cmdSelect.Parameters["@ID"].Value = 100; //this can be also an input for user etc.

yourSqlConn.Open();
byte[] img=(byte[])cmdSelect.ExecuteScalar();
string strfn=Convert.ToString(DateTime.Now.ToFileTime());
FileStream fs=new FileStream(strfn,FileMode.CreateNew, FileAccess.Write);
fs.Write(img,0,img.Length);
fs.Flush();
fs.Close();





查看以下文章了解更多详情:

使用Microsoft .NET从SQL Server存储和检索图像 [ ^ ]


你可以像这样保存,



Hi you can save like this,

string fname= System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
string activeDir = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "Temp";
System.IO.Directory.CreateDirectory(activeDir);
string newPath = System.IO.Path.Combine(activeDir, fname);
FileUpload1.PostedFile.SaveAs(newPath);


嗨...

如何存储&使用asp.net c#在mysql数据库中检索图像[ ^ ]



保存到文件夹:

Hi...
How to store & retrieve images in mysql database using asp.net c#[^]

for saving into folder:
//Get Filename from fileupload control
                string filename = Path.GetFileName(imgful.PostedFile.FileName);
                //Save images into foldername folder
                imgful.SaveAs(Server.MapPath("~/foldername/" + filename));



并写下你的插入查询。



谢谢你。


and write ur insert query.

thank u.