locked
BASE64 Type Column RRS feed

  • Question

  • User-640323567 posted

    Hi,
     
    I am binding data to a gridview where in one of the columns(documentbody) is a base64 type. Mostly, this will be a pdf or word document type.
    Now I would like to show documentbody column in gridview so the users can click on it and open the document. This is how I've been binding data to gridview. I am not sure how to proceed further for the above requirement.

       private void GetDataTable()
            {
                String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["Myaopcworkplacepocdev_MSCRMConnectionString"].ConnectionString;
    
                SqlConnection conn = new SqlConnection(strConnString);
    
                string strSelectCmd = "SELECT A.[new_type],A.[createdbyname], A.[createdon], [new_datereceived],B.FileName as FileName,B.DocumentBody as DocumentBody,B.MimeType as MimeType FROM Filterednew_document A inner join annotation B on A.new_documentid=B.ObjectId WHERE ([new_case2] = @new_case2name)";
                SqlCommand cmd = new SqlCommand(strSelectCmd);
    
                cmd.Parameters.AddWithValue("@new_case2name", lblId.Text);
    
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                conn.Open();
                cmd.Connection = conn;
                da.SelectCommand = cmd;
    
                da.Fill(dt);
    
                conn.Close();
    
                if (dt.Rows.Count > 0)
                {
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                }
                else if (dt.Rows.Count == 0)
                {
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                }
    
            }
    
    And Here is my gridview:
    
    
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
                <Columns>
                    <asp:BoundField DataField="createdbyname" HeaderText="Created By" SortExpression="createdbyname" />
                    <asp:BoundField DataField="new_typeofdocumentname" HeaderText="Document Name" SortExpression="new_typeofdocumentname" />
                    <asp:BoundField DataField="createdon" HeaderText="Created On" ReadOnly="True" SortExpression="createdon" />
                    <asp:BoundField DataField="new_datereceived" HeaderText="Date Received" ReadOnly="True" SortExpression="new_datereceived" />
                     <asp:BoundField DataField="FileName" HeaderText="File Nmae" ReadOnly="True" SortExpression="createdon" />
                    <asp:BoundField DataField="DocumentBody" HeaderText="Document Body" ReadOnly="True" SortExpression="new_datereceived" />
                     <asp:BoundField DataField="MimeType" HeaderText="MimeType" ReadOnly="True" SortExpression="new_datereceived" />
    
                </Columns>
                        </asp:GridView>

    Someone please guide me through this.
    Thanks for any input.

    Tuesday, June 21, 2016 6:00 PM

Answers