0

I'm using the Telerik RadGrid control and with it I'm using the GridAttachmentColumn as recommended on their documentation to download files but I seen to be missing something, perhaps some Code Behind? The documentation talks about disabling Ajax for file upload and exports but not download?

The SQL table contains the UNC path where these files are stored in a network share. The 'download' column points to the right data\location, the file path becomes a hyperlink but no action when I click on it.

I have also tried using a Hyperlink column which seems to partially work on IE but not on Chrome. Partially because some files are downloaded and some rendered on screen. I need to download them all with a solution that works on both browsers.

Here is the Grid code:

 <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" Skin="WebBlue" AllowPaging="True">
<GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>
        <MasterTableView AutoGenerateColumns="False" DataSourceID="SqlDataSource1" NoDetailRecordsText="No attachments to display.">
            <DetailTables>
                <telerik:GridTableView runat="server" DataKeyNames="SessionId" DataSourceID="SqlDataSource2" AllowPaging="False" PageSize="5" NoDetailRecordsText="No attachment to display.">
                    <Columns>
                        <telerik:GridAttachmentColumn DataSourceID="SqlDataSource2" HeaderText="Download" AttachmentDataField="DocName" AttachmentKeyFields="1" FileNameTextField="DocName" DataTextField="Path" UniqueName="Attachments" MaxFileSize="1048576">
                        </telerik:GridAttachmentColumn>
                    </Columns>
                </telerik:GridTableView>
            </DetailTables>
            <CommandItemSettings ShowAddNewRecordButton="False" ShowExportToExcelButton="True" ShowExportToPdfButton="True" ShowExportToWordButton="True" ShowRefreshButton="False" />
            <Columns>
                <telerik:GridBoundColumn DataField="SessionId" FilterControlAltText="Filter SessionId column" HeaderText="SessionId" SortExpression="SessionId" UniqueName="SessionId" Visible="False">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Ticket Number" FilterControlAltText="Filter TicketNumber column" HeaderText="Ticket Number" SortExpression="TicketNumber" UniqueName="TicketNumber">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Title" FilterControlAltText="Filter Title column" HeaderText="Title" SortExpression="Title" UniqueName="Title">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Description" FilterControlAltText="Filter Description column" HeaderText="Description" SortExpression="Description" UniqueName="Description" Visible="False">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="AffectedUser" FilterControlAltText="Filter AffectedUser column" HeaderText="AffectedUser" SortExpression="AffectedUser" UniqueName="AffectedUser">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="AssignedTo" FilterControlAltText="Filter AssignedTo column" HeaderText="AssignedTo" SortExpression="AssignedTo" UniqueName="AssignedTo">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Owner" FilterControlAltText="Filter Owner column" HeaderText="Owner" SortExpression="Owner" UniqueName="Owner">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Location" FilterControlAltText="Filter Location column" HeaderText="Location" SortExpression="Location" UniqueName="Location">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Resolution" FilterControlAltText="Filter Resolution column" HeaderText="Resolution" SortExpression="Resolution" UniqueName="Resolution">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Close Date" DataType="System.DateTime" FilterControlAltText="Filter CloseDate column" HeaderText="Close Date" SortExpression="CloseDate" UniqueName="CloseDate">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>

<FilterMenu RenderMode="Lightweight"></FilterMenu>

<HeaderContextMenu RenderMode="Lightweight"></HeaderContextMenu>
</telerik:RadGrid>

enter image description here

Hector Marcia
  • 103
  • 1
  • 12

2 Answers2

0

I'm guessing Telerik wasn't predicting UNC path usage for this control, it looks like you'll need to add some slashes and format it right to make the link fully clickable.

file://///server/path/to/file.txt

Even with this, it may not be fully cross-browser compatible. Accessing a local file from a website is a security risk.

Linking a UNC / Network drive on an html page

Seano666
  • 2,238
  • 1
  • 15
  • 14
  • Thanks for the answer Seano666. How would access or download a file from a network share within a grid column then? – Hector Marcia Mar 13 '19 at 13:41
  • You can format the path using the DataTextFormatString property. https://docs.telerik.com/devtools/aspnet-ajax/api/server/Telerik.Web.UI/GridAttachmentColumn – Seano666 Mar 13 '19 at 15:43
  • Thanks. Using Telerik grid is not working for me. I have opted to go the download page route. Considering the issue is accessing files in a remote share this should be a better option. – Hector Marcia Mar 13 '19 at 23:24
0

Addressed the issue with a different approach.

  • Changed to HyperLinkColumn
  • Used it as follow DataNavigateUrlFormatString="~\filedownload_6?FileName={0}"
  • Added a "Download Page"
  • Created a Virtual Directory in the website in IIS where the app is running which points to File Share and used it in the Server.MapPath Method. (~/Files/ in the code)

https://support.microsoft.com/en-ca/help/308150/how-to-create-a-virtual-directory-on-an-existing-web-site-to-a-folder

File Download Page code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DBSearchSolution
{
    public partial class filedownload_6 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //string filename = Request.QueryString["29215_1_0_image001.png"].ToString();
            string filename = Request.QueryString["FileName"].ToString();
            Response.ContentType = "application/octet-steam";
            Response.AppendHeader("content-disposition", "attachment; filename=" + filename);
            Response.TransmitFile( Server.MapPath("~/Files/" + filename));
            Response.End();
        }


    }
}
Hector Marcia
  • 103
  • 1
  • 12