문제

I am using HttpContext object implemented in HttpHandler child to download a file, when I have non-ascii characters in file name it looks weird in IE whereas it looks fine in Firefox.

below is the code:-

       context.Response.ContentType = ".cs";
context.Response.AppendHeader("Content-Length", data.Length.ToString());
context.Response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}",filename));
        context.Response.OutputStream.Write(data, 0, data.Length);

context.Response.Flush();

when I supply 'ß' 'ä' 'ö' 'ü' 'ó' 'ß' 'ä' 'ö' 'ü' 'ó' in file name field it looks different than what I have in file name it looks fine in firefox. adding EncodingType and charset has been of no use.

In ie it is 'ß''ä''ö''ü''ó''ß''ä''ö''ü'_'ó' and in firefox it is 'ß' 'ä' 'ö' 'ü' 'ó' 'ß' 'ä' 'ö' 'ü' 'ó'.

Any Idea how this can be fixed?

도움이 되었습니까?

해결책

이 기본 동작이므로 UPS에서 수동으로 광고 필드를 수동으로 맵핑해야합니다.

다른 팁

HttpUtility.UrlPathEncode might be a better option. As URLEncode will replace spaces with '+' signs.

For me this solution is working on all major browsers:

Response.AppendHeader("Content-Disposition", string.Format("attachment; filename*=UTF-8''{0}", HttpUtility.UrlPathEncode(fileName).Replace(",", "%2C"));
var mime = MimeMapping.GetMimeMapping(fileName);
return File(fileName, mime);

Using ASP.NET MVC 3.

The Replace is necessary, because Chrome doesn't like Comma (,) in parameter values: http://www.gangarasa.com/lets-Do-GoodCode/tag/err_response_headers_multiple_content_disposition/

문자 String.Format 문자열에는 3 개의 토큰이 있습니다. {0}, {1} 및 {2}

메인 문자열 외에도 메인 문자열 이외에 3 가지 변수를 전달할 것으로 기대합니다.

그러나 2 : $ listid, "{0}"

예제 :

$listID would map to {0}
"{0}" would map to {1}
nothing maps to {2}
.

http : //msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx 자세한 정보는

For me this solved the problem:

var result = new HttpResponseMessage(HttpStatusCode.OK)
{
   Content = new ByteArrayContent(data)
};

result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
    FileNameStar = "foo-ä-€.html"
};

When i look ad the repsonse in fiddler i can see the filename has automaticcaly been encoded using UTF-8:

Fiddler response example with encoded Content-Disposition filename using UTF-8

If we look at the value of the Content-Disposition header we can see it will be the same as @Johannes Geyer his answer. The only difference is that we didn't have to do the encoding ourselfs, the ContentDispositionHeaderValue class takes care of that.

I used the Testcases for the Content-Disposition header on: http://greenbytes.de/tech/tc2231/ as mentioned by Julian Reschke. Information about the ContentDispositionHeaderValue class can be found on MSDN.

For Asp.Net Core (version 2 as of this post) UrlPathEncode is deprecated, here's how to achieve the desired result:

System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
{
   FileName = Uri.EscapeUriString(fileName),
   Inline = true  // false = prompt the user for downloading;  true = browser to try to show the file inline
};

Response.Headers.Add("Content-Disposition", cd.ToString());

첨부 파일은 모든 SharePoint 목록에서 기술적으로 사용할 수 있습니다.목록의 정의에 따라 때로는 가려 질 수 있습니다.

블로그 게시 목록을 사용하면 활성화됩니다 (설정에서 볼 수 없음).게시물 목록의 목록보기 목록을 찾아서 게시물의 체크 표시를 선택하면 항목 아래의 리본에서 첨부 파일 옵션을 사용할 수 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top