Solved

Extracting blob data and binding to datagrid asp.net 1.1 vb.net

Posted on 2007-04-11
3
670 Views
Last Modified: 2012-05-05
Experts, I am trying to bind blob's do a datagrid which I have never done in asp.net 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?
0
Comment
Question by:tentavarious
  • 2
3 Comments
 
LVL 4

Expert Comment

by:jasco4617
ID: 18892442
Tentavarious,

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);
        Response.BinaryWrite(content);
        Response.End();
-------

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
0
 

Author Comment

by:tentavarious
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?
0
 
LVL 4

Accepted Solution

by:
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"];
        try
        {
            Int32.Parse(doc);
        }
        catch
        {
            Response.Redirect("Default.aspx");
        }

        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;
        cmd.Connection.Open();
        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();
            }
        }

        cmd.Connection.Close();

        Response.ContentType = contentType;
        Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
        Response.BinaryWrite(content);
        Response.End();
    }
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

919 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

20 Experts available now in Live!

Get 1:1 Help Now