Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在asp.net中打开名称中包含ambersand的文件时出错_C#_Javascript_Asp.net - Fatal编程技术网

C# 在asp.net中打开名称中包含ambersand的文件时出错

C# 在asp.net中打开名称中包含ambersand的文件时出错,c#,javascript,asp.net,C#,Javascript,Asp.net,我在打开文件时遇到了问题,ambersand在这两者之间 var attachment = "attachment;" + "&test& incident&.txt"; HtmlPage.Window.CreateInstance("foo2", new object[] { Id.ToString(), attachment }); function foo2(theAlert, type) { alert(type);

我在打开文件时遇到了问题,ambersand在这两者之间

var attachment = "attachment;" + "&test& incident&.txt";

 HtmlPage.Window.CreateInstance("foo2", new object[] { Id.ToString(), attachment });


function foo2(theAlert, type) {
            alert(type);
            window.open('fileViewer.aspx?Id=' + theAlert + '&Type=' + type);

        }
当我试图在另一页上输入时,我只得到了“附件”,因为它把单词放在了符号前面。我的文件名不见了。如果我给出的文件名没有符号,我在打开文件时没有任何问题

有人帮我吗

提前感谢。

请尝试以下操作:

window.open("fileViewer.aspx?Id=" + theAlert + "&Type=" + encodeURIComponent(type));
从encodeURI更改为encodeURI组件:

  • encodeURI用于完整URI
  • encodeURIComponent拟用于。。好。。URI组件是位于分隔符(;/?:@&=+$,#)之间的任何部分
您可以使用

函数的作用是:对URI组件进行编码

此函数用于对特殊字符进行编码。此外,它还对

以下字符:,/?:@&=+$#


这是因为,就URL.ya而言,符号就像一个保留字符,但在我的场景中,我必须使用。你能帮我解决这个问题吗?请尝试使用
attachment=attachment-HttpContext.Current.Server.UrlEncode(attachment)
它返回的attachmentTFS%3b不是整个文件名谢谢,我尝试了使用uri它不起作用。使用urimcomponent,工作正常。感谢您抽出时间分享此信息
window.open('fileViewer.aspx?Id=' + theAlert + '&Type=' + encodeURIComponent(type));