C# 在asp.net中打开名称中包含ambersand的文件时出错
我在打开文件时遇到了问题,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);
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组件是位于分隔符(;/?:@&=+$,#)之间的任何部分
这是因为,就URL.ya而言,符号就像一个保留字符,但在我的场景中,我必须使用。你能帮我解决这个问题吗?请尝试使用
attachment=attachment-HttpContext.Current.Server.UrlEncode(attachment)
它返回的attachmentTFS%3b不是整个文件名谢谢,我尝试了使用uri它不起作用。使用urimcomponent,工作正常。感谢您抽出时间分享此信息
window.open('fileViewer.aspx?Id=' + theAlert + '&Type=' + encodeURIComponent(type));