Friday, April 27, 2012

Down Load Files in Gridview using VB.NET


  <asp:GridView runat="server" ID="gridloadingdownload" Width="99%" DataKeyNames="attachdoc_id"
                    ShowHeaderWhenEmpty="true" AutoGenerateColumns="false" BorderColor="LightSkyBlue"
                    BorderWidth="1px">
                    <Columns>
                   
                        <asp:BoundField HeaderText="FileName" DataField="Filename" ItemStyle-Wrap="true">
                            <HeaderStyle BackColor="LightSkyBlue" Font-Bold="False" ForeColor="Black" HorizontalAlign="Left"
                                BorderColor="LightSkyBlue" BorderWidth="1px" />
                            <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="400Px" Wrap="true" BorderColor="LightSkyBlue" />
                        </asp:BoundField>
                        <asp:ButtonField ButtonType="Link" HeaderText="Download" Text="Download" CommandName="Download">
                            <HeaderStyle BackColor="LightSkyBlue" Font-Bold="False" ForeColor="Black" HorizontalAlign="Center"
                                BorderColor="LightSkyBlue" BorderWidth="1px" />
                            <ItemStyle HorizontalAlign="Center" VerticalAlign="Top" Width="30px" BorderColor="LightSkyBlue" />
                        </asp:ButtonField>
                    </Columns>
                </asp:GridView>




Private Sub gridloadingdownload_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gridloadingdownload.RowCommand
        Try
            If e.CommandName.ToString() = "Download" Then
                Dim id As Integer
                ' Response.Redirect("DownLoadForm.aspx")
                'lblClassID.Text = grdClasses.DataKeys(Convert.ToInt32(e.CommandArgument)).Value.ToString()
                id = Convert.ToInt64(gridloadingdownload.DataKeys(Convert.ToInt32(e.CommandArgument)).Value.ToString())
                Dim dtExcel = New System.Data.DataTable()
                dtExcel = DataConnect.GetInstance.GetDt("Select * from po_attachment where po_attachment_id=" & id)
                If dtExcel IsNot Nothing Then
                    Response.Clear()
                    Response.ContentType = "application/x-unknown"
                    Response.AppendHeader("Content-Disposition", "attachment; filename=" & dtExcel(0)("file_name").ToString())
                    Response.BinaryWrite(DirectCast(dtExcel(0)("file_content"), Byte()))
                End If
            End If
            hdnpackId.Value = "0"
            hdntypeid.Value = "0"
            cmbPFEPLabel1.Items.Clear()
            fillNLOadCombos()
        Catch ex As Exception
     
        End Try
    End Sub

No comments:

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...