473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Downloading Files stored in SQL Server

I am trying to download files from my database that I uploaded to it. I can
download bmp, txt file but have not been able to d/l pdf files. I am able to
d/l pdf files stored in the file system but not in the database. Any help
would be great. Here is my code, I have hard coded the file to download for
testing purposes.

Connect = "Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;Password=;Initial Catalog=INNB;Data Source=pompom"

Set db = Server.CreateObject("ADODB.Connection")
db.Open Connect

SQL = "SELECT filesize, contenttype, filename, filedata FROM thefiles where
id = 2"
Set rs = db.Execute( SQL )
If rs.EOF Then Response.End
Response.ContentType = "application/pdf"
Response.AddHeader "Content-Disposition", "attachment;filename=agencies.pdf"
Response.AddHeader "Content-Length", "16863"
Response.BinaryWrite rs("filedata")

Thanks,
Brett Bishop
MCSE, MCP+I
US Bankruptcy Court
Jul 22 '05 #1
1 1913

fibreiv wrote:
I am trying to download files from my database that I uploaded to it. I can download bmp, txt file but have not been able to d/l pdf files. I am able to d/l pdf files stored in the file system but not in the database. Any help would be great. Here is my code, I have hard coded the file to download for testing purposes.

Connect = "Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;Password=;Initial Catalog=INNB;Data Source=pompom"

Set db = Server.CreateObject("ADODB.Connection")
db.Open Connect

SQL = "SELECT filesize, contenttype, filename, filedata FROM thefiles where id = 2"
Set rs = db.Execute( SQL )
If rs.EOF Then Response.End
Response.ContentType = "application/pdf"
Response.AddHeader "Content-Disposition", "attachment;filename=agencies.pdf" Response.AddHeader "Content-Length", "16863"
Response.BinaryWrite rs("filedata")


So what kind of error do you get? How do you know the length is
16863??

When I do my binary retrieves I don't specify the length.

Here's my generic getbinary.asp page... When a file is uploaded I store
the mime type of the file.

<!-- #INCLUDE VIRTUAL="/adovbs.inc" -->

<%
ID = Request.QueryString("ID")
tablename=Request.QueryString("tablename")
idfieldname=Request.QueryString("idfieldname")
datafield=Request.QueryString("datafield")
datacon=session("DB_CONNECTIONSTRING")
Set con2 = Server.CreateObject("ADODB.Connection")
Con2.open(datacon)

mysql2="select * from " & tablename &" where "& idfieldname & "=" & ID
Set rs2=con2.execute(mysql2)

if not rs2.EOF then
Response.ContentType = rs2("type_"&right(datafield,
len(datafield)-4))
Response.BinaryWrite(rs2(datafield))
else
Response.Write("Record '" + ID + "' not found.")
end if

rs2.Close
%>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta name="Microsoft Theme" content="none, default">
</head>

Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Henke | last post by:
I have a web application that is used to transfer files to and from a database. The files are streamed and stored in the database that is. From one page I can download the files to the client, by...
3
by: ACaunter | last post by:
Hi all, I was wondering if there was a way a client's machine could play audio or view a word document which is stored on the server, without having them download it first. This will be done over...
4
by: Himanshu | last post by:
hi, Can anybody tell me that thru asp.net using c#, how can we upload and download physical files in any table of SQL Server Database. the uploading part is running successfully but the...
6
by: Shawn | last post by:
Hi. How can I download a file and store it on the web server. I have a complete URL to the file, but I never know what kind of file it is. It can be pdf, jpg, tif, doc, xls etc. Thanks, Shawn
2
by: Bala | last post by:
Hi I am trying to download the PDF files from my webserver using ASP.Net. All my files are stored at F Drive on webserver. Like this F:\Main Folder\Sub Folder\Files\File1.pdf I am...
1
by: just.starting | last post by:
Hi, My dot net client downloads files and checks for any new files time to time. The server is apache2.0.53 server. So what happens is that my file download thing works fine if I dont try to call...
3
by: just.starting | last post by:
Hi, My dot net client downloads files and checks for any new files time to time. The server is apache2.0.53 server. So what happens is that my file download thing works fine if I dont try to call...
8
by: Jeppe Dige Jespersen | last post by:
I am building a page that takes a single parameter: documentId. I have documents stored in a SQL Server 2005 database. Storing and retrieving these from a WinForms application works fine. No...
14
by: suryadithya | last post by:
Hi, I am very new to php. And I have got to submit a project very soon (By tomorrow evening). So please help. The problem is this. I have created a file upload mechanism where the uploaded files...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.