Last Updated: 29 May 2020 15:15 by ADMIN
Created on: 11 Feb 2019 10:24
Category: UI for ASP.NET AJAX
Type: Feature Request
GridAttachmentColumn passes malformed file path to the DataSource
GridAttachmentColumn malforms the String filepath, from "C\SomePath\SomeFile.PDF" to something like "C:" & vbBack &"SomePathSomeFile.PDF"

Steps to reproduce the error:

DataSource Bound to grid:

Private Function SomeTable() As DataTable
    Dim dt As New DataTable()
    dt.Columns.Add(New DataColumn("FieldName", Type.GetType("System.String")))
    row("FieldName") = "C:\SomeDirectory\RadGridExport.pdf"
    Return dt
End Function

GridAttachmentColumn markup as well as the ObjectDataSource that returns a byte array when user clicks on download attachment:

<telerik:GridAttachmentColumn DataSourceID="ObjectDataSource1"
    HeaderText="Attachment Column"
    ItemStyle-Width="36px" >
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="MySelectMethod" TypeName="MyApp">
        <asp:Parameter Name="FieldName" Type="String" />

MyApp.MySelectMethod that is supposed access the file by "filePath" and read it to byte, but the filePath is malformed, hence throws an exception.

Public Class MyApp
    <DataObjectMethodAttribute(DataObjectMethodType.Select, True)>
    Public Function MySelectMethod(filePath As String) As DataTable
        Dim dt As New DataTable("Base")
        Dim col As New DataColumn("FieldName")
        col.DataType = System.Type.GetType("System.Byte[]")
        Dim row As DataRow = dt.NewRow
        row(0) = My.Computer.FileSystem.ReadAllBytes(filePath)
        Return dt
    End Function
End Class

1 comment
Peter Milchev
Posted on: 29 May 2020 15:15

A temporary workaround:

Using the ItemCommand event handler of the Grid, you can get the correct Path (value) and save it in a flag variable (filePath) like the example below:

Dim filePath As String
Protected Sub RadGrid1_ItemCommand(sender As Object, e As GridCommandEventArgs)
    If e.CommandName = "DownloadAttachment" Then
        filePath = DirectCast(e.Item, GridDataItem).GetDataKeyValue("PDF")
    End If
End Sub

Wire up the OnSelecting server event to the ObjectDataSource

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetPDFByFileName" TypeName="MyApp"
        <asp:Parameter Name="PDF" Type="String" />

In the Selecting event handler, access the value of the flag (filePath) and change the parameters for the PDF object, to send the correct format into the code behind:

Protected Sub ObjectDataSource1_Selecting(sender As Object, e As ObjectDataSourceSelectingEventArgs)
    If Not String.IsNullOrEmpty(filePath) Then
        Dim params As OrderedDictionary = e.InputParameters
        params("PDF") = filePath
    End If
End Sub


Peter Milchev
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.