You must Sign In to post a response.
  • Category: ASP.NET

    Download a file from database using asp.net c# code in page load event

    Dear All

    Dear All

    I want to download a file from database using asp.net c# code in page load event.

    My table design as below

    Table Name: tblFiledownload
    Id - int
    Data - varbinary(MAX)
    FileName - varchar(50)
    FileExtension - varchar(50)

    Could you please help me from this issue.

    Thanks
    Sathik
  • #761562
    Hi,

    Please refer below articles for more details and sample code,
    http://www.dbtutorials.com/advanced/retrieving-binary-sql-cs/

    http://www.codeproject.com/Articles/32216/How-to-store-and-fetch-binary-data-into-a-file-str

    http://stackoverflow.com/questions/20173448/retrieve-video-file-stored-as-varbinary-in-sql-server-express-database


    Regards,
    Asheej T K
    Microsoft MVP[ASP.NET/IIS]
    DotNetSpider MVM

  • #761569
    Basically you have to do the following

    Response.BinaryWrite(bytes);
    Response.Flush();
    Response.Close();

    You can try the following in the page load

    Response.Clear();
    Response.Buffer = true;
    Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", "FileName"));
    Response.ContentType = "your content type";
    Response.BinaryWrite(YourData);
    Response.End();

    By Nathan
    Direction is important than speed


Sign In to post your comments