Login
Register
Tutorials
Forum
Career Development
Resources
Reviews
Jobs
Interview
Communities
Projects
Training
Silverlight Games
|
Bookmarks
|
New Members FAQ
|
Mentor
|
Code Converter
|
IT Companies
|
Peer Appraisal
|
Members
|
Revenue Sharing
|
Computer Jokes
|
New Posts
|
Social
|
Talk to Webmaster Tony John
Online Members
Ultimaterengan
Padma
Ankesh Kumar
Ram
mohanraj
Ranjith Kumar
Asheej T K
More...
Forums
»
.NET
»
ASP.NET
»
How to display a pdf file stored as a image type in DB
Posted Date:
27 Nov 2009
Posted By::
k.anantharengan
Member Level:
Gold
Member Rank:
709
Points
: 1
Responses:
1
I had uploaded a pdf file in my application and saved it as an image datatype in SQL server 2005 table.I had used the code below .I checked the DB it is getting the file in a binary format .My question is how to display the Pdf file stored in DB ?.if i select a pdf file stored in a table it should open in a new window.
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Connection1 obj=new Connection1 ();
SqlConnection connection = obj.Connect();
try
{
int number = Convert.ToInt32(TextBox1.Text.ToString());
FileUpload img = (FileUpload)FileUpload1;
Byte[] imgByte = null;
if (img.HasFile && img.PostedFile != null)
{
Response.Write("hello");
HttpPostedFile File =FileUpload1.PostedFile;
imgByte = new Byte[File.ContentLength];
int s= imgByte.GetLength(0);
Response.Write(s.ToString());
File.InputStream.Read(imgByte, 0, File.ContentLength);
}
connection.Open();
string sql = "INSERT INTO pdfs1 VALUES('"+imgByte+"',"+number+")";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.ExecuteNonQuery ();
}
catch
{
// lblResult.Text = "There was an error";
}
finally
{
connection.Close();
}
}
Thanks in advance.
Tweet
Responses
#448011 Author:
Anuraj
Member Level:
Gold
Member Rank:
105
Date: 27/Nov/2009 Rating:
Points
: 2
Check this link
http://www.dotnetthoughts.net/2009/10/07/how-to-store-and-retrieve-files-from-sql-server-database/
Thanks
Anuraj
You can follow me in twitter : http://www.twitter.com/anuraj
http://www.dotnetthoughts.net
Post Reply
This thread is locked for new responses. Please post your comments and questions as a
separate thread
.
If required, refer to the URL of this page in your
new post
.
Tweet
Next :
Refresh login page after giving userid....and Operator '==' cannot be applied to operands
Previous :
How to interchange the rows in sql
Return to Discussion Forum
Post New Message
Category:
Related Messages
Validation Controls
no of click on advertisement in asp.net application
Please Please help.................. tooo urgent
Please tell me .Net interview Questions for 2+ Years Exp
To upload Documents like(doc,pdf,etc) to file system
Active Members
Today
daisy520
(10)
Ultimaterengan
(7)
nadh
(5)
Last 7 Days
baskar
(312)
naveensanagase...
(183)
Asheej T K
(163)
more...
Awards & Gifts
Email subscription
.NET Jobs
.NET Articles
.NET Forums
Articles Rss Feeds
Forum Rss Feeds