ASP.NET MVC: Can an MSI file be returned via FileContentResult without breaking the installation package?

I use this code to return a FileContentResult with an MSI file to be downloaded by a user in my ASP.NET MVC :

using (StreamReader reader = new StreamReader(@"c:\WixTest.msi")) { Byte[] bytes = Encoding.ASCII.GetBytes(reader.ReadToEnd()); return File(bytes, "text/plain", "download.msi"); } 

I can download the file, but when I try to run the installer, I get an error message:

This installation package cannot be opened. Contact your application vendor to verify that this is a valid Windows Installer package.

I know that the problem is not in C: \ WixTest.msi, because it works fine if I use a local copy. I don’t think I am using the wrong MIME type because I can get something like this just using File.Copy and returning the copied file via FilePathResult (without using StreamReader), which works correctly after loading.

I need to use FileContentResult so that I can delete a copy of the file that I create (which I can do as soon as I load it into memory).

I think I invalidate the installation package by copying or encoding the file. Is there a way to read the MSI file in memory and return it using FileContentResult without damaging the installation package?

Decision:

 using (FileStream stream = new FileStream(@"c:\WixTest.msi", FileMode.Open)) { BinaryReader reader = new BinaryReader(stream); Byte[] bytes = reader.ReadBytes(Convert.ToInt32(stream.Length)); return File(bytes, "application/msi", "download.msi"); } 
+4
source share
1 answer

Try using binary encoding and the application/msi content type instead of text/plain - it's not ASCII or text content, so you are managing the file.

+3
source

Source: https://habr.com/ru/post/1303159/


All Articles