.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How do I display excel, pdf and word binary data in a gridview?

Posted By:      Posted Date: September 21, 2010    Points: 0   Category :ASP.Net

Hello forum

I'm using the following code to upload images, pdf files, word files and excel to a sql table as binary data.  However, I can only figure out how to display the images but am clueless about the other type of files.  What adjustments do I need to make so that with a button click I can access the other files?  't By the way, I'm using an image control to display the binary data and I'm aware that that will only work to display images, I just don't how to access all the other types of files once uploaded. Thanks

Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Data.SqlClient
Imports System.IO

Partial Class Uploads_UReceipts
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Request.QueryString("ImageID") IsNot Nothing Then

            Dim strQuery As String = "select Name, ContentType, Data from tblFiles where id=@id"

            Dim cmd As SqlCommand = New SqlCommand(strQuery)

            cmd.Parameters.Add("@id", SqlDbType.Int).Va

View Complete Post

More Related Resource Links

display data into GridView from excel sheet

I have to display data from excel sheet into my gridview and also I need to figure out a way to store data into excel files from my web page. I am using C# 3.5, VS 2008.

Display data in gridview dynamicallay

I have AD domain which has 100000 users, I want to display all the users in gridview controls.Actually it is displaying users in gridview after parsing entire domain which takes around 30 min. I want to display the users while loading itself.It is continously getting user information from AD domain and getting each user details, I want to display the users information which already queried instead of waiting till getting all users information

asp.net display data in gridview

i want to display data in gridview binded to a sql datasource
but the problem part is i want to bind a field of that datasource to a dropdownlist and when a item is selected in that dropdownlist then correcposnding to that data will be displayed in gridview...

Display Related Data in an ASP.NET GridView

Typically when you display a datagrid you will want to show data from a related table. There are 3 different ways to accomplish this with NetTiers. You can use a custom stored procedure, deepload functionality from the code behind, or a strongly typed datasource control. We'll provide an example of each

Export Gridview data to Excel sheet


Hi ,

     I have a requirement where i need to export the gridview data to excel.My code export the data in excel that was fine.

But the enchancement needed now , I was exporting the 3 gridview in same excel sheet under the workbook.

Now i need to export the 3 grid view in 3 different sheet in the same workbook.

so can please tell or share the updated code in my below code ...

public void writeovrsummary()


        Response.Write("Overall Summary");
        //Response.Write("Report as of " + DateTime.Now.ToString("hh:mm ss tt"));

        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);

        SqlCommand com = MyConnection.CreateCommand();
        com.CommandText = "useroverall_Report";
        SqlParameter[] par = new SqlParameter[1];
        par[0] = new

display data in excel 2007


 I am using .net  version 1.1  and  excel 2003 to display data.I need to display data in 2007 .Can  anyone suggest the reference to be added ,connection string change and what should be imported.  

Create excel file from Binary data on SqlServer



My requirement is that i upload an excel file then i need to validate that data.


1. Uploading file using using upload control saving binary in SqlServer

2. Then i am creating file from binary data  on Sql Server using below command and then using OPENROWSET to dump data to Sql table

3. Then reading Sql Table row wise and validating data.


Alter Procedure spUploadExcelFile
  @PKID int,
  @BatchID int


	Declare @VarBin varbinary(max)
	Declare @FileName varchar(100)
	DECLARE @sql nvarchar(MAX)
                DECLARE @errMsg nvarchar(MAX)
	DECLARE @ObjectReturn INT
	DECLARE @ErrorSource VARCHAR(255)
	DECLARE @ErrorDesc VARCHAR(255)
	DECLARE @ObjectToken INT

	Select @VarBin  = Content , @FileName = [FileName] from MultilangBinaryData Where PKID = @PKID
	SET @FileName = 'C:\'  + @FileName
	EXEC sp_OACreate 'ADODB.Stream' @ObjectToken OUTPUT
	EXEC sp_OASetProperty @ObjectToken, 'Type', 1
	EXEC sp_OAMethod @ObjectToken, 'Open'
	EXEC sp_OAMethod @ObjectToken, 'Write', NULL, @VarBin
	EXEC sp_OAMethod @ObjectToken, 'SaveToFile', NULL, @FileName, 2
	EXEC sp_OAMethod @ObjectToken, 'Close'
	EXEC sp_OADestroy @ObjectToken  
	SET @sql = 'INSERT INTO dbo.UserBulkData SELECT 0,NULL,'+ @BatchI

String Data missing start from "+" When Export Data To Excel Using Gridview

Hi,I am exporting data from gridview to excel file.My problem is that for all the string which contain "+", the rest of data begining from it is missing in excel file.For example: PWE-WER+78, when exported it will become PWE-WER.Below is my code.                Response.ClearContent() Response.Buffer = True Response.AddHeader("Content-Disposition", "attachment;filename=" & "ExportedExcel.xls") Response.ContentType = "application/vnd.ms-excel" Response.Charset = "" lobjStringWriter = New StringWriter lobjHtmlWriter = New HtmlTextWriter(lobjStringWriter) dgdResult.RenderControl(lobjHtmlWriter) Response.Write(lobjStringWriter.ToString()) Response.End() I  have search through online but no solution.Does anyone has idea on this?

excel to gridview, lost data?!

I don't know why.... I can't understand I import by fileupload one xls, I open this one and I would connect it to a gridview.Everythings works fine but when I see the gridview I don't understand why some data is not available  HttpPostedFile xls = this.FileUpload1.PostedFile; string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + xls.FileName.ToString() + ";Extended Properties=Excel 8.0"; DataTable dt = new DataTable(); DataSet ds = new DataSet(); OleDbConnection oConn = new OleDbConnection(); oConn.ConnectionString = strConn; oConn.Open(); List<string> fogli = new List<string>(); //recupero i nomi dei fogli del file excel dt = oConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,null); foreach (DataRow tt in dt.Rows) { fogli.Add(tt["TABLE_NAME"].ToString()); } dt.Clear(); System.Data.OleDb.OleDbDataAdapter ExcelAdapter = new System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [" + fogli[162].ToString() + "]", oConn); ExcelAdapter.Fill(ds); gvExcel.DataSource = ds.Tables[0].DefaultView; gvExcel.DataBind();First I get the name of all the sheets and after I fill one

ajax accordion with gridview doesn't display data


hi guys,

im trying to display some data using a gridview inside ajax accordion. i have called the method accordion1_itemBound at the accordion properties but it still doesnt show me any data at the gridview... i check all my query string and everything seems find. would really appreciate if someone could check my code and teach me how to solve it.

below are my codes at the source page

    <form id="form1" runat="server">
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ProrsumDBConnectionString %>" 
            SelectCommand="SELECT [reviewID], [comments], [reviewDate] FROM [Review]">
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        <asp:DataList ID="dlProdCatalog" runat="server">
                <asp:Image ID="Image2" runat="server" ImageUrl='<%# Eval("pictureURL") %>' />
                <br />
                Tour Title:
                <asp:Label ID="tourTitle

Display XML Data in GridView Dynamically


how to display data in gridview dynamically using code behind, if the xml data is available in string variable (i don't want to use xml file for carrying data). plz let me know as soon as possible

export the gridview data to excel problem



i am using master page and child pages in the child page

i want to export the gridview data to excel sheet for this i use the following code


        Response.AddHeader("content-disposition", "attachment; filename=shedules.xls");

        Response.ContentType = "application/excel";

        StringWriter sw = new StringWriter();

        HtmlTextWriter htw = new HtmlTextWriter(sw);




but in the gridShedules.RenderControl(htw) i got the following error but the form tag with  runat= server is already in the master page how to solve this issue

error:Control 'ctl00_ContentPlaceHolder1_grdshedules' of type 'GridView' must be placed inside a form tag with runat=server.

Read and display the excel data


I have 3 excel files having uniqe column Name JobNo. i want to develop a web page containing serach option based on Jobno.

User just type the jobno and press on search button corresponding record should be display on grid view.record may present any of the excel sheet.how can i acheive this.please provide me the code.


How to insert Binary Image data from XML To Excel using XSLT


Hi All,

I had created a XSLT which converts the XML file generated from the system to the excel format. The XSLT has the styles required for this transformation.

Now i am told to insert image in one of the excel columns using XSLT. The image is in binary code format in the XML file.

Tried to google but could not found the syntaxes for this. Let me know if anyone has done the image embedding in excel using XSLT.


Writing data from Gridview to Excel spreadsheet


Found code to do this but get an error I cannot correct.

Error is:

Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.

This statement gives me the error: gv.RenderControl(htw)

Any help is really appreciated.  I got this cod from other threads in here

Here is the asp and the vb code:

Main asp page:

<form id="form1" runat="server">
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
            AllowSorting="True" DataSourceID="SqlDataSource1" Width="809px">
                <asp:CommandField ShowDeleteButton="True" />

Display data in GridView


I'm trying to display soma data in a gridview. This is my table below:

ID    Book                                   Rating

2    ONE GIANT LEAP                   2
3    SPIDERS                               na
4    RULES    
5    NO TALKING                          1
8    SPIDERS                                4
9    NO TALKING                          na

Customizing GridView to display and edit boolean data



I'm quite new to ASP.NET programming, so excuse me if my question is dumb.

I have the need of showing a grid (A GridView ?)  of boolean values. But instead of showing checkboxes, I want to show the cells filled with black (value is true) or white (value is false). I understand I can do that by crafting a TemplateField and changing the style of the cell to select the correct background color and never displaying an actual value. I have not tried but I think it could work. The grid will contains 99% of boolean values and will contain something like 20 rows of 100 columns (2000 cells).

Now I would like to have that grid edited in place at client side, that is with JavaScript, changing the style of the cell when the user clicks on the cell. There would be a submit button somewhere to postback the whole thing.

Is that possible ? Any hint for programming it ?

Since I have a lot of webforms which needs to display that kind of grid, I would like to go further and design a custom GridView (or other control) that I could install in the toolbox and reuse easily.

Any help appreciated.


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend