我用byte[]将文件存到oracle中数据类型为<BLOB>
但我从数据库中取出来的时候,变为了System.Byte[].
我怎么将System.Byte[]转换出来。让我读到文件的相关信息(如文件名,类型等。。) //获取二进制文件
private byte[] GetFileContent(FileUpload File)
{
byte[] b=null;
if (File.Visible = true && File.HasFile)
{
b = File.FileBytes;
}
else
{
b = new byte[0];
}
return b;
}
但我从数据库中取出来的时候,变为了System.Byte[].
我怎么将System.Byte[]转换出来。让我读到文件的相关信息(如文件名,类型等。。) //获取二进制文件
private byte[] GetFileContent(FileUpload File)
{
byte[] b=null;
if (File.Visible = true && File.HasFile)
{
b = File.FileBytes;
}
else
{
b = new byte[0];
}
return b;
}
{
FileStream aFile = new FileStream("Temp.txt", FileMode.Create);
aFile.Seek(0, SeekOrigin.Begin);
aFile.Write(b, 0, b.Length); //将字节数据写入文件
}
catch (IOException ex)
{
Console.WriteLine(ex.ToString());
Console.ReadKey();
return;
}
page_load()
{
byte[] b =null;
b = engineering.EngineeringsNoticeplan; //实体属性 byte[]
string ctype = GetContentType(engineering.NoticeplanFilename); //文件下载类型
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8)); //Response.ContentEncoding = System.Text.Encoding.GetEncoding("Shift_JIS")
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
//Response.ContentType = "text/plain"
HttpContext.Current.Response.ContentType = ctype;
HttpContext.Current.Response.BinaryWrite(b); HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();
HttpContext.Current.Response.End();
}//判断文件类型返回下载类型
///////////////////////////////////////////////////////////////////////
public string GetContentType(string filename)
{
//string ext = System.IO.Path.GetExtension(filename).ToLower();
string ext = filename.Substring((filename.LastIndexOf('.'))).ToLower(); if (ext == ".jpg"
|| ext == ".jpeg")
{
return "image/jpeg";
}
else if (ext == ".gif")
{
return "image/gif";
}
else if (ext == ".bmp")
{
return "image/bmp";
}
else if (ext == ".tiff")
{
return "image/tiff";
}
else if (ext == ".txt" || ext == ".ini" || ext == ".bat" || ext == ".js")
{
return "text/plain";
}
else if (ext == ".doc" || ext == ".docx")
{
return "application/msword";
}
else if (ext == ".xls")
{
return "application/excel";
}
else if (ext == ".zip")
{
return "application/zip";
}
else if (ext == ".htm"
|| ext == ".html"
|| ext == ".asp"
|| ext == ".aspx"
|| ext == ".php")
{
return "text/html";
}
else if (ext == ".xml")
{
return "text/xml";
}
else
{
return "";
} }
FileStream fs = new FileStream(@"D:\22-11-46-3-524454584.jpg",FileMode.Open,FileAccess.Read);
byte[] mydata = new byte[fs.Length];
int Length = Convert.ToInt32(fs.Length);
fs.Read(mydata,0,Length);
fs.Close();
this.Response.OutputStream.Write(mydata,0,Length);
this.Response.End();