I am using vb.net and I have got it working uploading and retrieving files
into an image datatype. The only type I havent got to work is pdf.
Here is my code:
' Uploading
fLen = myFile.ContentLength
Dim fBuffer(fLen) As Byte
myFile.InputStream.Read(fBuffer, 0, fLen)
' myFile is of type HttpPostedFile
dr("mcontent") = fBuffer
dr("ilength") = fLen
'Downloading
dr = dt.Rows(0)
Dim fBuffer(dr("ilength")) As Byte
fBuffer = dr("mcontent")
Response.ContentType = dr("cContentType")
'Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", _
"attachment; filename=" & dr("cfilename"))
Response.OutputStream.Write(fBuffer, 0, dr("ilength")
I hope this helps
[quoted text, click to view] "Charlie@CBFC" <charle1@comcast.net> wrote in message
news:eB6VfhkTFHA.2996@TK2MSFTNGP15.phx.gbl...
> Hi:
>
> I'm uploading documents into a SQL Server Image field and using
> Response.BinaryWrite() to download or view them in the browser. Some doc
> types like Adobe Illustrator and Photoshop files will open correctly, but
> other like Word, Excel and Powerpoint are corrupt. Here is code fragment
> to
> upload:
>
> // Get file in byte array
> int fileLen = this.TextBoxFileToUpload.PostedFile.ContentLength;
> byte[] arrayFile = new byte [fileLen];
> Stream strm = this.TextBoxFileToUpload.PostedFile.InputStream;
> string contentType = this.TextBoxFileToUpload.PostedFile.ContentType;
> strm.Read(arrayFile, 0, fileLen);
>
> // Run insert commands...
>
> Here is download code fragment:
>
> // Get data into a reader...
>
> // write to browser
> Response.ContentType = reader["ContentType"].ToString();
> Response.AppendHeader("Content-Disposition", "attachment; filename = " +
> fileName);
> Response.BinaryWrite((byte[]) reader["FileContents"]);
>
> Should work, seems like I'm missing something.
>
> Thanks,
> Charlie
>
>