Method for Download a document file from datatable using c#.net

The following  method is for download a document file from datatable .I am taking a column name as Document.


Write this method in any pageload (or) in any button click event:


     private void download(DataTable dt)
     {
        Byte[] bytes = (Byte[])dt.Rows[0]["Document"];
        Response.Buffer = true;
        Response.Charset = "";
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.ContentType = dt.Rows[0]["DocumentType"].ToString();
        Response.AddHeader("content-disposition", "attachment;filename="
        + dt.Rows[0]["NameOfDocument"].ToString());
        Response.BinaryWrite(bytes);
        Response.Flush();
        Response.End();
    }


0 comments:

Post a Comment