Change file name before responce

Hi!

I have file to response: FileInfo fileResponse;
and I need before sending to change the file name.

Doing so

var result = new HttpResult(fileResponse, asAttachment: true);
result.Headers["Content-Disposition"] = t.Headers["Content-Disposition"].Replace("oldFileName", "newFileName");

It works )) but this is not correct, maybe there’s another variant to do this?

Thanks!

The convenience constructor that takes a FileInfo populates the Content-Disposition header from the FileInfo object as expected. Replacing the fileName is one solution otherwise you’d need to populate the Content-Disposition header yourself, e.g:

var result = new HttpResult(fileResponse, asAttachment: true);
result.Headers["Content-Disposition"] = $$"attachment; filename=\"{newName}\"; size={fileResponse.Length}; modification-date={fileResponse.LastModified.ToString("R").Replace(",", "")}";

Thanks for the reply :grinning: