如何将图像从sql数据库保存到文件夹中 [英] How to save Image into folder from sql database

查看:92
本文介绍了如何将图像从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();





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

< a href =http://www.codeproject.com/KB/database/ImageSaveInDataBase.aspx>使用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.


这篇关于如何将图像从sql数据库保存到文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆