Saving ntext data from SQL Server to file directory using asp
Posted
by April
on Stack Overflow
See other posts from Stack Overflow
or by April
Published on 2010-03-15T17:50:41Z
Indexed on
2010/03/15
19:09 UTC
Read the original article
Hit count: 221
A variety of files (pdf, images, etc.) are stored in a ntext field on a MS SQL Server. I am not sure what type is in this field, other than it shows question marks and undefined characters, I am assuming they are binary type.
The script is supposed to iterate through the rows and extract and save these files to a temp directory. "filename" and "contenttype" are given, and "data" is whatever is in the ntext field.
I have tried several solutions:
1) data.SaveToFile "/temp/"&filename, 2
Error: Object required: '????????????????????'
???
2) File.WriteAllBytes "/temp/"&filename, data
Error: Object required: 'File'
I have no idea how to import this, or the Server for MapPath. (Cue: what a noob!)
3)
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
BinaryStream.Type = adTypeBinary
BinaryStream.Open
BinaryStream.Write data
BinaryStream.SaveToFile "C:\temp\" & filename, adSaveCreateOverWrite
Error: Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
4)
Response.ContentType = contenttype
Response.AddHeader "content-disposition","attachment;" & filename
Response.BinaryWrite data
response.end
This works, but the file should be saving to the server instead of popping up save-as dialog. I am not sure if there is a way to save the response to file.
Thanks for shedding light on any of these problems!
© Stack Overflow or respective owner