如何下载具有特殊字符的文件。 [英] How to download file with special character.

查看:85
本文介绍了如何下载具有特殊字符的文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有文件名的文件

特殊字符 - ! @#$%^& ()_ + = - {} _' - ..xlsx无法下载。



请在下面找到我使用的代码段。



在rowdatabound客户端..



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..

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);





这里我得到了FilePath然后它将设置为rgAttachment_RowDataBound里面的onclick方法,请看下面





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

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



但是onclick没有使用上面提到的文件名触发。




However onclick is not firing with the filename mentioned above.

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;
}

推荐答案

%^& ()_ + = - {} _' - ..xlsx无法下载。



请在下面找到我使用的代码段。



在rowdatabound客户端..



% ^ & () _ + =- {} _ ' -`.xlsx and unable to download.

Please find below the code snippet i used.

In rowdatabound client side..

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);





这里我得到了FilePath然后它将设置为rgAttachment_RowDataBound里面的onclick方法,请看下面





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

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



但是onclick没有使用上面提到的文件名触发。




However onclick is not firing with the filename mentioned above.

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;
}


错误来自于您通过GET请求传递文件名。要完成这项工作,您需要首先对文件名进行URL编码:



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;
}


这篇关于如何下载具有特殊字符的文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆