数据库中的二进制文件如何还原并保存
发布网友
发布时间:2022-04-28 20:12
我来回答
共3个回答
热心网友
时间:2022-06-23 01:25
文件存库里面啊?那多占空间啊!加载是很慢的!是不是图片?
这里有个操作物理路径下载的函数:
private void FileDown(string strPath)
{
System.IO.FileInfo file = new System.IO.FileInfo(strPath);
if (file.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(file.FullName, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Filter.Close();
Response.WriteFile(file.FullName);
Response.End();
}
else
{
ClientScript.RegisterStartupScript(GetType(), "", "<script language='javascript'>alert('文件不存在!');</script>");
}
}
如果是存取图片的话:
存:
FileStream fs = new FileStream(FilePath, FileMode.OpenOrCreate, FileAccess.Write);
byte[] myData = new byte[fileStream.Length];
fileStream.Read(myData, 0, System.Convert.ToInt32(fileStream.Length));//从流中读取字节块,并将数据写入到该缓冲区
fileStream.Close();
...把mydata插入到数据库就好勒!
取:
取出byte[]来,直接image.formStream(fs);
热心网友
时间:2022-06-23 01:25
byte[] data 16进制
System.IO.StreamWriter objwrite = new System.IO.StreamWriter(path);
objwrite.BaseStream.Write(data,0,data.Length);
objwrite.Close();
热心网友
时间:2022-06-23 01:25
fhj