Hello, I am trying to create a way for the user to view a pdf, xlsx, jpg, gif, etc., from a link button within my Detail table in a radgrid. I am able to accomplish this for a pdf, but not the image files or Excel files.
One of the main issues is that the file types stored within the SQL table field can be any of those above types. My question is how can I write the vb.net code to display any type of file from the same RadGrid column; as the Details Table can have numerous records of different file types.
Here's what I have --
01.<DetailTables>02. <telerik:GridTableView DataKeyNames="fileID" Name="Attachments" DataSourceID="sdsVenFiles" CommandItemDisplay="Top" Caption="Files Attached to this Vendor Maintenance Request:"03. NoDetailRecordsText="No files are attached to this Vendor Adjustment request." Width="75%" EditFormSettings-FormCaptionStyle-Font-Bold="true">04. <ParentTableRelation>05. <telerik:GridRelationFields DetailKeyField="wfID" MasterKeyField="wfID" />06. </ParentTableRelation>07. <CommandItemSettings ShowAddNewRecordButton="false" ShowRefreshButton="true" />08. <Columns>09. <telerik:GridBoundColumn SortExpression="fileID" HeaderText="File ID" HeaderButtonType="TextButton" DataField="fileID" Visible="false"></telerik:GridBoundColumn>10. <telerik:GridBoundColumn SortExpression="wfID" HeaderText="Control #" HeaderButtonType="TextButton" DataField="wfID" Visible="false"></telerik:GridBoundColumn>11. <telerik:GridTemplateColumn HeaderText="Open File">12. <ItemTemplate>13. <asp:LinkButton ID="lnkDownload" runat="server" Text='<%# Eval("fileName")%>' OnClick="viewFile" CommandArgument='<%# Eval("fileID")%>'></asp:LinkButton>14. </ItemTemplate>15. </telerik:GridTemplateColumn>16. 17. <telerik:GridButtonColumn CommandName="Delete" ConfirmText="Delete this file?" HeaderText="Delete" Text="Delete" UniqueName="DeleteColumn1">18. </telerik:GridButtonColumn>19. </Columns>20. </telerik:GridTableView>21. </DetailTables>
And my vb.net --
01.Protected Sub viewFile(sender As Object, e As EventArgs)02. 03. Dim id As Integer = Integer.Parse(TryCast(sender, LinkButton).CommandArgument)04. Dim bytes As Byte()05. Dim fileName As String, contentType As String06. Dim constr As String = ConfigurationManager.ConnectionStrings("DbName").ConnectionString07. Using con As New SqlConnection(constr)08. Using cmd As New SqlCommand()09. cmd.CommandText = "SELECT fileID, fileName, fileType, fileData FROM tblVendorFile WHERE fileId=@Id"10. cmd.Parameters.AddWithValue("@Id", id)11. cmd.Connection = con12. con.Open()13. Using sdr As SqlDataReader = cmd.ExecuteReader()14. sdr.Read()15. bytes = DirectCast(sdr("fileData"), Byte())16. contentType = sdr("fileType").ToString()17. fileName = sdr("fileName").ToString()18. End Using19. con.Close()20. End Using21. End Using22. 23. Response.Clear()24. Response.Buffer = True25. Response.Charset = ""26. Response.Cache.SetCacheability(HttpCacheability.NoCache)27. Response.ContentType = "application/pdf"28. Response.BinaryWrite(bytes)29. Response.Flush()30. Response.End()31. 32. End Sub
Thanks for any and all help!
