Solved

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

Posted on 2008-10-23
4
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Author Comment

by:rshafakian
ID: 22790888
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
ID: 22797955
Not sure if it is going to work, if not, then sorry:
Try removing "Response.Clear();"
0
 

Author Comment

by:rshafakian
ID: 22798001
Yeah that didn't work
0
 
LVL 51

Accepted Solution

by:
Ted Bouskill earned 500 total points
ID: 22801695
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

751 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