Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i download files from gridview and i am done with that like this

C#
Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView1.SelectedIndexChanged
    Dim strKeyName() As String = {"DocID"}
    Dim objKeyVal() As Object = {GridView1.SelectedRow.Cells(1).Text}
    Dim DocExte As String = ""
    Dim DocuName As String = ""
    structDb = objDataSet.ExecSP("tbl", "getdoc", strKeyName, objKeyVal)
    If structDb.intCode = 0 Then
        Return
    Else
        If structDb.dstResult.Tables(0).Rows.Count > 0 Then
            For i = 0 To structDb.dstResult.Tables(0).Rows.Count - 1
                Dim binary() As Byte = TryCast(structDb.dstResult.Tables(0).Rows(i).Item("document"), Byte())
                Dim ms As MemoryStream = New MemoryStream(binary)
                DocExtension = structDb.dstResult.Tables(0).Rows(i).Item("DocExte")
                DocumentName = Now.Day & Now.Month & Now.Year * Now.Hour & Now.Minute & Now.Millisecond & DocExtension
                Response.Clear()
                Response.Buffer = True
                Response.Charset = ""
                Response.Cache.SetCacheability(HttpCacheability.NoCache)
                Response.ContentType = ContentType
                Response.AppendHeader("Content-Disposition", Convert.ToString("attachment;filename=") & DocuName )
                Response.BinaryWrite(binary)
                Response.Flush()
                Response.[End]()
            Next
        End If
    End If

End Sub

now i try to download from data list but in data list how i get value i.e. documentid from data list as i get this value from gridview through cells now how i modify according to data list

data list cod

What I have tried:

<asp:DataList ID="dl_Options" runat="server" Width="100%" DataKeyField="HisIndex" BorderColor="Black" BorderStyle="Solid" Font-Bold="False" BackColor="White" BorderWidth="0px">
                                <ItemTemplate>

                                    <table class="colordtd">
                                        <tr>
                                            <td class="ProductPropertyLabel" width="100px">Customer Responce:</td>
                                            <td>
                                                <asp:Label ID="Label5" runat="server" Text='<%# Eval("GroupName") %>' /></td>
                                            <td class="ProductPropertyLabel" width="100px">Entry Date:</td>
                                            <td width="100px">
                                                <asp:Label ID="Label6" runat="server" Text='<%# Eval("EntryDate") %>' />
                                        </tr>
                                        <tr>
                                            <td class="ProductPropertyLabel" width="100px">Remarks:</td>
                                            <td width="300px">
                                                <asp:Label ID="Label8" runat="server" Text='<%# Eval("Remarks") %>' /></td>
                                            <td class="ProductPropertyLabel" width="100px">File:</td>
                                              <asp:HiddenField ID="HiddenFieldDocID"
                                                runat="server" Value='<%# Eval("DocumentID")%>' /> 
                                            <td width="100px">
                                                <asp:LinkButton ID="lnkDownload" runat="server" CausesValidation="False" 
                                        CommandArgument='<%# Eval("FileName")%>'  
                                        CommandName="Download" Text='<%# Eval("FileName")%>' />                                                                   
                                        </tr>
                                    </table>

                                </ItemTemplate>
                            </asp:DataList>

get doc sp is

select DocID,document,DocuName ,DocExte from Downloads where DocumentID = @DocumentID 

now i modify according to like for download documents

Protected Sub DownloadFile(sender As Object, e As EventArgs)
    Dim strKeyName() As String = {"DocID"}
    Dim ID As Guid = Guid.Parse(DirectCast(FindControl("HiddenFieldDocID"), HiddenField).Value)
    Dim objKeyVal() As Object = {ID}
    Dim DocExte As String = ""
    Dim DocuName As String = ""
    structDb = objDataSet.ExecSP("tbl", "getdoc", strKeyName, objKeyVal)
    If structDb.intCode = 0 Then
    Return
    Else
        Dim count As Integer = dl_Options.Items.Count
        For i As Integer = 0 To count - 1
            Dim binary() As Byte = TryCast(dl_Options.Items(i),("document"), Byte())
            Dim ms As MemoryStream = New MemoryStream(binary)
            DocExte = structDb.dstResult.Tables(0).Rows(i).Item("DocExtension")

            DocumentName = Now.Day & Now.Month & Now.Year * Now.Hour & Now.Minute & Now.Millisecond & DocExte 

            Response.Clear()
            Response.Buffer = True
            Response.Charset = ""
            Response.Cache.SetCacheability(HttpCacheability.NoCache)
            Response.ContentType = ContentType
            Response.AppendHeader("Content-Disposition", Convert.ToString("attachment;filename=") & DocuName )
            Response.BinaryWrite(binary)
            Response.Flush()
            Response.[End]()
        Next

    End If

End Sub

when i try this shows an error

Type expected.

on this line

Dim binary() As Byte = TryCast(dl_Options.Items(i),("document"), Byte())
Posted
Updated 18-Jan-17 8:54am

1 solution

Quote:
Dim binary() As Byte = TryCast(dl_Options.Items(i),("document"), Byte())

Looks like you've got a stray comma in there. TryCast only accepts two arguments. Try:
Dim binary() As Byte = TryCast(dl_Options.Items(i)("document"), Byte())


Also, it's "Customer Response", not "Customer Responce". :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900