Click here to Skip to main content
15,888,315 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have file with file name
special character- ! @ # $ % ^ & () _ + =- {} _ ' -`.xlsx and unable to download.

Please find below the code snippet i used.

In rowdatabound client side..

C#
function rgAttachment_RowDataBound(sender, eventArgs) {
    var res = "";
    if (eventArgs != null) {
        var gridItem = eventArgs.get_item();
        var rowElement = eventArgs.get_item().get_element();
        if (gridItem != null) {
            try {
                var rowIndex;
                try { rowIndex = eventArgs.get_item()._element.rowIndex.toString() }
                catch (sError) { rowIndex = eventArgs._element.rowIndex.toString() }
                var FilePath1 = eventArgs.get_dataItem()["FilePath"];
                var FilePath=encodeURI(FilePath1);


Here i got the FilePath then it will set into onclick method inside rgAttachment_RowDataBound please see below

C#
var imgViewAttachment = sender.get_masterTableView().getCellByColumnUniqueName(eventArgs.get_item(), "imgViewAttachment");
                imgViewAttachment.setAttribute('onclick', 'ViewAttachment(\'' +FilePath+ '\');');
                imgViewAttachment.title = "View Attachment";

However onclick is not firing with the filename mentioned above.

C#
function ViewAttachment(filePath) {
    
    var w = 600, h = 540;
    if (document.all) {
        /* the following is only available after onLoad */
        w = document.body.clientWidth;
        h = document.body.clientHeight;
    }
    else if (document.layers) {
        w = window.innerWidth;
        h = window.innerHeight;
    }

    var popW = 100, popH = 100;
    var leftPos = (w - popW) / 2, topPos = ((h - popH) + 100) / 2;
    window.open('../Pages/FileReader.aspx?fileName=' + filePath +'&PageFrom=REPORTS', '', "scrollbars=yes,resizable=yes,width=" + popW + ",height=" + popH + ",top=" + topPos + ",left=" + leftPos);
    return false;
}
Posted
Updated 17-Dec-15 23:21pm
v2
Comments
ZurdoDev 18-Dec-15 8:36am    
Sounds like you need to rename your files before trying to download them.

What is the exact error you get?

1 solution

The error comes from that you are passing your filename through a GET reqest. To make this work you need to URL encode your filename first:

function ViewAttachment(filePath) {
    
    var w = 600, h = 540;
    if (document.all) {
        /* the following is only available after onLoad */
        w = document.body.clientWidth;
        h = document.body.clientHeight;
    }
    else if (document.layers) {
        w = window.innerWidth;
        h = window.innerHeight;
    }
 
    var popW = 100, popH = 100;
    var leftPos = (w - popW) / 2, topPos = ((h - popH) + 100) / 2;
    window.open('../Pages/FileReader.aspx?fileName=' + encodeURI(filePath) +'&PageFrom=REPORTS', '', "scrollbars=yes,resizable=yes,width=" + popW + ",height=" + popH + ",top=" + topPos + ",left=" + leftPos);
    return false;
}
 
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