Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To put it into the database you must read it into a byte array. Either read it from the file system or use the AspNetFileUploadWebControl.FileBytes property. Create an insert stored procedure and add the byte array as the parameter for your DB column (the column must be of SQL data type "image").</p> <p>To get it out of the database, use something like:</p> <pre><code>theRow = getDatarowFromDatabase(); aByteArrayOfTheFile = (byte[])theRow["theSqlImageColumnWithTheFileInIt"]; </code></pre> <p>To allow the user to view or download it use my method SendAsFileToBrowser():</p> <pre><code>SendAsFileToBrowser(aByteArrayOfTheFile, "application/pdf", "downloaded.pdf"); </code></pre> <p>The source code for the method (with overloads):</p> <p><code></p> <pre><code> // Stream a binary file to the user's web browser so they can open or save it. public static void SendAsFileToBrowser(byte[] File, string Type, string FileName) { string disp = "attachment"; if (string.IsNullOrEmpty(FileName)) { disp = "inline"; } // set headers var r = HttpContext.Current.Response; r.ContentType = Type; // eg "image/Png" 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(); // write data to requesting browser r.BinaryWrite(File); r.Flush(); } //overload public static void SendAsFileToBrowser(byte[] File, string Type) { SendAsFileToBrowser(File, Type, ""); } // overload 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); } </code></pre> <p></code></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload