Solved

How to output a text file that was uploaded to MS SQL image type

Posted on 2008-10-23
4
206 Views
Last Modified: 2012-05-05
I'm taking over a project and the DB that I have has a table with a field that's type image.  I think this might just be a text file, but I'm not certain.  It might end up being a PDF or a word doc or something.  Can someone help me or point me in the right direction in outputing this data?  I need to show it on a page.
0
Comment
Question by:rshafakian
  • 2
4 Comments
 

Author Comment

by:rshafakian
Comment Utility
Okay I got it working with the code below, but now my problem is that I cannot get it so it displays in the correct area of the page.  Like I have section in my page that displays this data, but I cannot get it to spit out in this area of the page.  It just shows the document and nothing else.  I lose everyrthing that's on my master page (header, menu items, footer, etc...)
        string strTest = "SELECT DESCRIPTION FROM News WHERE News_id = 3841";

        SqlCommand commTest;

        SqlDataReader rderTest;
 

        commTest = new SqlCommand(strTest, sqlConn);

        rderTest = commTest.ExecuteReader();

        if (rderTest.Read() == true)

        {

            arrFile = (byte[])(rderTest["DESCRIPTION"]);

            Response.Clear();

            Response.Buffer = true;

            Response.ContentType = "text/html";

            BinaryWriter bw = new BinaryWriter(Response.OutputStream);

            

            bw.Write(arrFile);
 

            //Response.Flush();

            //Response.End();

        }

Open in new window

0
 
LVL 22

Expert Comment

by:prairiedog
Comment Utility
Not sure if it is going to work, if not, then sorry:
Try removing "Response.Clear();"
0
 

Author Comment

by:rshafakian
Comment Utility
Yeah that didn't work
0
 
LVL 51

Accepted Solution

by:
tedbilly earned 500 total points
Comment Utility
I'm typing from memory so there might be some errors, however, this is the gist of it.
        string strTest = "SELECT DESCRIPTION FROM News WHERE News_id = 3841";

        SqlCommand commTest;

        SqlDataReader rderTest;

 

        commTest = new SqlCommand(strTest, sqlConn);

        rderTest = commTest.ExecuteReader();

        if (rderTest.Read() == true)

        {

            Stream s = new MemoryStream((byte[])rderTest["DESCRIPTION"]);

            Response.Clear();

            Response.Buffer = true;

            Response.ContentType = "text/html";

            Response.OutputStream.Write(s);

            Response.Flush();

            Response.End();

        }

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now