, . , AspNetFileUploadWebControl.FileBytes. DB ( SQL "" ).
, - :
theRow = getDatarowFromDatabase();
aByteArrayOfTheFile = (byte[])theRow["theSqlImageColumnWithTheFileInIt"];
, SendAsFileToBrowser():
SendAsFileToBrowser(aByteArrayOfTheFile, "application/pdf", "downloaded.pdf");
( ):
public static void SendAsFileToBrowser(byte[] File, string Type, string FileName)
{
string disp = "attachment";
if (string.IsNullOrEmpty(FileName))
{
disp = "inline";
}
var r = HttpContext.Current.Response;
r.ContentType = Type;
r.Clear();
r.AddHeader("Content-Type", "binary/octet-stream");
r.AddHeader("Content-Length", File.Length.ToString());
r.AddHeader("Content-Disposition", disp + "; filename=" + FileName + "; size=" + File.Length.ToString());
r.Flush();
r.BinaryWrite(File);
r.Flush();
}
public static void SendAsFileToBrowser(byte[] File, string Type)
{
SendAsFileToBrowser(File, Type, "");
}
public static void SendAsFileToBrowser(System.IO.Stream File, string Type, string FileName)
{
byte[] buffer = new byte[File.Length];
int length = (int)File.Length;
File.Write(buffer, 0, length - 1);
SendAsFileToBrowser(buffer, FileName, Type);
}
>