Thursday, March 22, 2012

Download Documents From Database

Does anyone have a code snippet in VBScript for how allow a user to save (or open) a document that has been stored in a database?

I have documents that are stored in an image column in a database. I have the code I need to upload documents from a user's browser. I'm not having any luck, however, figuring out how to let the user view or download the document that has been stored.

Regards,

Hugh ScottI'm no developer but found interesting code snippets from Planet SC (http://www.planet-source-code.com/).

HTH|||Sorry,

I had the code snippet right under my nose. This is VBScript:

<%
Set Conn = GetConnection
Set adoRS = Server.CreateObject("ADODB.Recordset")

'Open dynamic recordset, table Upload
adoRS.Open "SELECT * FROM tbl_Documents WHERE DocumentID = 1", Conn, 2, 2

sFileName = adoRS("SourceFileName")
sContentType = adoRS("ContentType")
sDataSize = adoRS("DataSize")

' clear the buffer
Response.Buffer = True
Response.Clear


' send the headers to the users browser
Response.AddHeader "Content-Disposition", "attachment; filename=" & sFileName
' Response.AddHeader "Content-Length", sDataSize
Response.Charset = "UTF-8"
Response.ContentType = scontentType

' output the file to the browser
Response.BinaryWrite adoRS("Data")
Response.Flush


' tidy up
s.Close
Set s = Nothing

Function GetConnection()
dim Conn

Set Conn = CreateObject("ADODB.Connection")

Conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=iEIC;Data Source=MyServer"

Conn.Open

set GetConnection = Conn
end function
%>

Originally posted by hmscott
Does anyone have a code snippet in VBScript for how allow a user to save (or open) a document that has been stored in a database?

I have documents that are stored in an image column in a database. I have the code I need to upload documents from a user's browser. I'm not having any luck, however, figuring out how to let the user view or download the document that has been stored.

Regards,

Hugh Scott

No comments:

Post a Comment