This is a migrated thread and some comments may be shown as answers.

Validate filename in attachment column before uploading

1 Answer 30 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Felice asked on 01 Sep 2013, 03:27 PM
I am experiencing some problem with the filename of some document.

The users print out articles from internet and upload them as they are using the upload button of the attachmentcolumn. The problem comes when in the file name there are chars like < > ' which in our case cause exceptions.
To avoid the problem I would like to filter (strip out those special chars from the filename) before uploading.
To do so I need to get access to the filename of the file before it gets uploaded, manage it and pass it back to the attachmentcolumn control.
How can I achieve that?

1 Answer, 1 is accepted

Sort by
Jayesh Goyani
Top achievements
Rank 2
answered on 02 Sep 2013, 05:33 AM

<telerik:RadCodeBlock ID="telerikodeBlock1" runat="server">
       <script type="text/javascript">
           function ClientFileSelected(sender, args) {
               //Access your file name here
               var filePath = sender.getFileInputs()[0].value;
               var fileName = filePath.substring(filePath.lastIndexOf("\\") + 1);
               //Remove File IF it is not valid
               var fileInputs = sender.getFileInputs();
               for (var i = fileInputs.length - 1; i >= 0; i--) {
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
               <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
               <telerik:GridAttachmentColumn UniqueName="AttchColumn">
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
       dynamic data1 = new[] {
              new { ID = 1, Name ="Name_1"},
              new { ID = 2, Name = "Name_2"},
              new { ID = 3, Name = "Name_3"},
              new { ID = 4, Name = "Name_4"},
              new { ID = 5, Name = "Name_5"}
       RadGrid1.DataSource = data1;
   protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
       if (e.Item.IsInEditMode && e.Item is GridEditableItem)
           GridEditableItem item = e.Item as GridEditableItem;
           RadUpload ru = item["AttchColumn"].Controls[0] as RadUpload;
           ru.OnClientFileSelected = "ClientFileSelected";

Jayesh Goyani
Asked by
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question