Extracting blob data and binding to datagrid 1.1

Posted on 2007-04-11
Last Modified: 2012-05-05
Experts, I am trying to bind blob's do a datagrid which I have never done in 1.1.  We have a database table that stores pdf's, docs, and gif's as blobs.  How do I extract blob's and bind it to a datagrid?
What I would like to do in the datagrid is have a hyper link column that when clicked displays the blob in its format as doc, pdf, gif etc.  Any ideas?
Question by:tentavarious
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

Expert Comment

ID: 18892442

You would need to have a page, lets call it download.aspx and pass it a document ID that would be the the primary key for the column that has the stored blob data.

you would then need to have a query that pulls that information from the database and use that data to modify the http header for the request and stream the blob data.  See the below example.

        Byte[] content = new Byte[0];
        String filename = "";
        String contentType = "";

        Response.ContentType = contentType;
        Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);

You would set the appriate variable information from what was returned in your query.   for this to work correctly, you must have the contentType (mime type) or else the browser will not know how to work with the data.

I hope this answers your question and points you in the right direction.

- pat

Author Comment

ID: 18897912
i was actually looking for maybe and example of using a datareader or dataset to read in the blob column.  Is there something special I need to do?

Accepted Solution

jasco4617 earned 250 total points
ID: 18898575
Here is an example from .net 2.0....i am not sure if this is the same with 1.1 or not though (i think it is, give it a shot):

protected void Page_Load(object sender, EventArgs e)
        String doc = Request.QueryString["doc"];

        SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["SQLConnString"].ConnectionString);
        SqlCommand cmd = new SqlCommand("SELECT files.*, fileTypes.* FROM files INNER JOIN fileTypes ON files.typeID = fileTypes.typeID WHERE fileID=@fileID", conn);
        cmd.Parameters.Add("@fileID", SqlDbType.Int).Value = doc;
        SqlDataReader reader = cmd.ExecuteReader();
        Byte[] content = new Byte[0];
        String filename = "";
        String contentType = "";
        if (reader.HasRows)
            while (reader.Read())
                contentType = reader.GetValue(6).ToString();

                //content = new Byte[reader.GetInt32(7)];
                content = reader.GetSqlBytes(5).Buffer;
                //reader.GetBytes(5, 0, content, 0, reader.GetInt32(7));
                filename = reader.GetValue(1).ToString();


        Response.ContentType = contentType;
        Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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 …
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL ( and MongoDB (…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

729 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