I have a function in the controller that downloads a configurations:
public FileStreamResult SaveData()
{
var toJson = JsonConvert.SerializeObject(this.GetData());
var byteArray = System.Text.Encoding.ASCII.GetBytes(toJson);
var stream = new MemoryStream(byteArray);
string fileName = "Configuration.json";
this.GetData().Save = false;
return new FileStreamResult(stream, "text/html")
{
FileDownloadName = fName
};
}
It works fine, but the only issue is that it downloads file automatically. I want to provide a user with a possibility to update the name and set the download location, i.e. I want a "save as" dialog to popup prior to download.
I looked multiple sources, but cannot find something, which will be applicable. Can anyone suggest, how it should be done?
Thanks in advance.
Different browsers behave differently regarding the displaying of a Save As dialog. The only way to have any control is to not give the browser cues as to the data type or name of the file. In these cases browsers have no choice but to ask the user for a filename.
Replace "text/html" with "application/octet-stream". this says "here is a bunch of bytes, but I don't know what they represent".
Remove the
FileDownloadName. If the browser doesn't have a name, it will need to ask for one.You may need to do one or both of the above, depends on the browsers you care about.