2008-08-06 10:46:00 UTC
Hi, i am uploading a .docx file into sql2005 and later when i retrieve the
file from the database and i open it, i get a error message "The file is
corrupted and cannot be open". I am not facing this issue when i store and
retrieve files of type .doc
i am storing the file in a column of datatype image.
Here is the code where i insert the file into database. Am sure the code is
working.
Am using VB Script here.
Set dbRS = server.createObject("ADODB.Recordset")
dbRS.Open "attachment", dbConn, 3, 3
dbRS.AddNew
dbRS.Fields("attachment_name").Value = File.FileName
dbRS.Fields("attachment_size").Value = File.FileSize
dbRS.Fields("attachment_mime").Value = File.ContentType
dbRS.Fields("id").Value = request.querystring("id")
dbRS.Fields("feedback_attachment_data").AppendChunk File.FileData & ChrB(0)
dbRS.Update
dbRS.Close
Here is the code where i retrieve the file from the database.
set dbRS = dbConn.execute("SELECT attachment_name, attachment_mime,
attachment_data FROM attachments WHERE (attachment_id = " &
Request.QueryString("id") & ")")
If Not dbRS.EOF Then
Response.ContentType = dbRS("attachment_mime")
Response.AddHeader "Content-Disposition", "attachment;filename=" &
dbRS("attachment_name")
Response.BinaryWrite dbRS("attachment_data")
Else
Response.Write("File could not be found")
End If
Please let me know as to why i am not able to retrieve the .docx files
properly.
file from the database and i open it, i get a error message "The file is
corrupted and cannot be open". I am not facing this issue when i store and
retrieve files of type .doc
i am storing the file in a column of datatype image.
Here is the code where i insert the file into database. Am sure the code is
working.
Am using VB Script here.
Set dbRS = server.createObject("ADODB.Recordset")
dbRS.Open "attachment", dbConn, 3, 3
dbRS.AddNew
dbRS.Fields("attachment_name").Value = File.FileName
dbRS.Fields("attachment_size").Value = File.FileSize
dbRS.Fields("attachment_mime").Value = File.ContentType
dbRS.Fields("id").Value = request.querystring("id")
dbRS.Fields("feedback_attachment_data").AppendChunk File.FileData & ChrB(0)
dbRS.Update
dbRS.Close
Here is the code where i retrieve the file from the database.
set dbRS = dbConn.execute("SELECT attachment_name, attachment_mime,
attachment_data FROM attachments WHERE (attachment_id = " &
Request.QueryString("id") & ")")
If Not dbRS.EOF Then
Response.ContentType = dbRS("attachment_mime")
Response.AddHeader "Content-Disposition", "attachment;filename=" &
dbRS("attachment_name")
Response.BinaryWrite dbRS("attachment_data")
Else
Response.Write("File could not be found")
End If
Please let me know as to why i am not able to retrieve the .docx files
properly.
--
SUNNY
SUNNY