473,396 Members | 1,766 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.

C#-WEB:Open a PDF saved in the database

10
In my progr, users can upload PDF files which are saved in SQL Server. But when I try to retrieve the file, it just won't open. I am using the following code:

_ObjUC = new UserControls();
DataTable dt = new DataTable();

_ObjUC.DocumentID = Request.QueryString["id"].ToString().Trim();
dt = _ObjUC.getPDFdocument(_ObjUC.DocumentID);

byte[] buffer = (byte[])dt.Rows[0]["document_content"];

Response.ContentType = "application/pdf";
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("content-disposition", "inline;filename=file.pdf");
MemoryStream PageData = new MemoryStream(buffer);
PageData.WriteTo(Response.OutputStream);

We use a shared development environment. The funny thing is that it works on my collegues comp but not on mine. We both user IE 7.0. Am I doing something wrong here? Is there an alternate way?
Apr 9 '07 #1
10 2320
Motoma
3,237 Expert 2GB
When you say "won't open" what do you mean? What happens? Do you get a save dialog and the file is corrupted, or will it not download at all?
Apr 9 '07 #2
ftech
10
No ... all I get is a blank screen
Apr 10 '07 #3
Motoma
3,237 Expert 2GB
Blank screen in what? Adobe? IE? Firefox? PLEASE WORK WITH ME HERE!
I can only be as helpful as you are!
Apr 10 '07 #4
ftech
10
the blank screen is IE
Apr 10 '07 #5
ftech
10
What I am doing is that I am displaying the name of the pdf files in a gridview. When the user clicks on a particular name, I grab the document's id and get the document (which was originally a pdf doc) from the database and display it to the user. But when I do this using the above code, I get a blank IE screen. I tried to debug this and it does not result in any errors. so i don't know whats wrong?
Apr 10 '07 #6
Motoma
3,237 Expert 2GB
And it works on your co-workers box? Have you tried other machines in your office to ensure this is not a browser problem?
Apr 10 '07 #7
ftech
10
yeah ... it just works on one of by colleague's machine ... I tried it on a few other folks machine but it does not work on theirs.
Apr 10 '07 #8
Motoma
3,237 Expert 2GB
yeah ... it just works on one of by colleague's machine ... I tried it on a few other folks machine but it does not work on theirs.
This may have to do with some sort of pathing issue. Where are the PDFs located in relation to your machine? How is this different from your co-worker's? You may be storing the wrong path to the PDF...did your co-worker upload it from his computer by any chance? Take a look at the database...do all of the paths look correct to you?
Apr 10 '07 #9
ftech
10
yeah it looks fine ... all I am doing is grabbing the file content from the database (SQL Server). I then cast it as a byte array and use the above code to display it. Path is certainly not the issue here.
Apr 10 '07 #10
ftech
10
I figured out that the above code works fine if I change the content-disposition to 'attachment' . But I don't know why it does not work when I change it to 'inline'
Apr 11 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Andras Gilicz | last post by:
Hi VB fans I'm working on a relatively large project in VB6 with about a dozen forms, including graphs, labels, text boxes, etc. The software itself is actually a flow simulator with more or...
3
by: VbUser25 | last post by:
hi.. i have a form i accept some user inputs in the form. there is a link on the form from where i open the excel file in the same browser (not in a new page...simply using a href. i am also...
46
by: Steve | last post by:
Access97 Database The database is split into a frontend and backend and not connected to any other database. The database has an unbound report with 15 subreports. Some of the subreports include...
15
by: dixie | last post by:
I have a command to open the Access Options dialogue from code: DoCmd.RunCommand acCmdOptions It also opens the Database Window behind it. Is it possible to open the Options without having...
5
by: deko | last post by:
I use hyperlinks in a subform datasheet to display locally saved documents that are associated with individual database entries. A customer entry may have a list of invoices in pdf format, for...
5
by: Mike Turco | last post by:
This is the second day with the second database from a second person on a second computer that I have had this problem. When somebody emails a database to me and I try to open it, I first get a...
4
by: jefftim | last post by:
Hi All I've saved a word document in sql server database.I'm able to retrieve it from the database and open it in a word application. My problem is as i have to use this in an intranet...
0
by: jefftim | last post by:
Hi All I've saved a word document in sql server database.I'm able to retrieve it from the database and open it in a word application. My problem is I'm able to open it in server/client machines...
2
by: jefftim | last post by:
Hi All I've saved a word document in sql server database.I'm able to retrieve it from the database and open it in a word application. My problem is I'm able to open it in server/client machines...
7
by: owuraku | last post by:
Hi fellas I have a list of Databases named to reflect the current working month and year. Each month a copy of the past month's database is saved and the name is changed to the present month. For...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.