Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# angular 4下载pdf文件为空_C#_Angular - Fatal编程技术网

C# angular 4下载pdf文件为空

C# angular 4下载pdf文件为空,c#,angular,C#,Angular,您好,我正在尝试从服务器上创建的报告下载pdf。当我创建它时,我会在服务器上保存一会儿,然后再打第二个电话下载它 以下是web API上的代码: var rootDirectory = HostingEnvironment.MapPath("~"); var filePath = $@"{rootDirectory}\Temp\{file}.pdf"; var bytes = File.ReadAllBytes(filePath);

您好,我正在尝试从服务器上创建的报告下载pdf。当我创建它时,我会在服务器上保存一会儿,然后再打第二个电话下载它

以下是web API上的代码:

        var rootDirectory = HostingEnvironment.MapPath("~");
        var filePath = $@"{rootDirectory}\Temp\{file}.pdf";
        var bytes = File.ReadAllBytes(filePath);
        File.Delete(filePath);

        var memoryStream = new MemoryStream(bytes);

        var result = new HttpResponseMessage(HttpStatusCode.OK)
        {
            Content =  new ByteArrayContent(memoryStream.ToArray())
        };
        result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
        {
            FileName = "report.pdf"
        };
        result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");

        return result;
然后我回到typescript,下面是我下载时使用的代码:

                this.reportsService
                    .download(id)
                    .subscribe(r => {
                        let pdf =r._body;
                        var pdfName = `${this.selectedReport.name}.pdf`;
                        let blob = new Blob([pdf], { type: 'application/pdf' });

                        window.open(URL.createObjectURL(blob));
                    });

            });
我应该提到,当我从服务器上保存pdf的位置打开pdf时,它是正确的。
有人能告诉我我遗漏了什么吗?

调试时,
r.\u body
的值是多少?看起来像是下载的字节。有人知道吗?