Benjamin Stucki
Benjamin Stucki

Reputation: 53

Action Result File - Filename when downloading is wrong in some cases

So this is the Code that returns the file. It is in a Method named GetMainReport.

var mBytes = MergePDF(formLanguage, mergedForms);
                        if (mBytes != null)
                        {
                            var cd = new System.Net.Mime.ContentDisposition
                            {
                                FileName = formLanguage.FileName,
                                Inline = formLanguage.FileExtension == FileExtension.PDF
                            };

                            Response.Headers.Add("content-disposition", cd.ToString());

                            AddDownloadedForm(formLanguage.Id);
                            return File(mBytes, type);
                        }

My Problem now is that if i go via this url: http://localhost:8090/Library/105020.pdf The filename when downloaded is 105020.pdf

if i use this one

http://localhost:8090/FormSearch/FormSearch/getMainReport?FormNumber=105020%20%20de

The filename is GetMainReport.pdf

any ideas why?

Upvotes: 2

Views: 79

Answers (1)

Christian L.
Christian L.

Reputation: 290

try this settings for ContentDisposition:

 var cd = new System.Net.Mime.ContentDisposition
  {
    FileName = formLanguage.FileName,
    DispositionType = DispositionTypeNames.Attachment,
    Inline = formLanguage.FileExtension == FileExtension.PDF
   };

Upvotes: 1

Related Questions