我正在使用 ac# web api 控制器,我的代码应该在其中创建几个 word 文档并将它们压缩到一个 zip 文件中。我正在使用 Ionic.Zip 压缩文件并将其作为输入参数返回到下面的代码中。该代码应该将 zip 文件推送给用户进行下载,但它是在窗口中加载 zip 文件。
我正在使用以下代码:
protected HttpResponseMessage ZipContentResult(ZipFile zipFile)
{
// inspired from http://stackoverflow.com/a/16171977/92756
var pushStreamContent = new PushStreamContent((stream, content, context) =>
{
zipFile.Save(stream);
stream.Close(); // After save we close the stream to signal that we are done writing.
}, "application/zip");
return new HttpResponseMessage(HttpStatusCode.OK) {Content = pushStreamContent};
}
但是当我运行它时,zip 文件会加载到窗口中,而不是提示保存文件。
这是我运行它时得到的:
PKxS�I$$filedocumentname.docx
�0�L�G@.�L�G@.�L���UP@�-JB��ew.
�\��u��$8��;0�\w�����Su�s��y��z��U�]�ת���*�3r,�L6zy4�O00>`a`�a�xj���i��i���f�a��������S��O1���F��pQ�x�R��
�W�ȟ<vJS�8ZTGCZ�Y/....
关于我做错了什么或如何解决这个问题的任何想法?
非常感激。