Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

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

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
rshafakian
Asked:
rshafakian
  • 2
1 Solution
 
rshafakianAuthor Commented:
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
 
prairiedogCommented:
Not sure if it is going to work, if not, then sorry:
Try removing "Response.Clear();"
0
 
rshafakianAuthor Commented:
Yeah that didn't work
0
 
Ted BouskillSenior Software DeveloperCommented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now