Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.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
.net 如何在Typescript中解析C#FileContentResult_.net_Angular_.net Core_Angular2 Forms - Fatal编程技术网

.net 如何在Typescript中解析C#FileContentResult

.net 如何在Typescript中解析C#FileContentResult,.net,angular,.net-core,angular2-forms,.net,Angular,.net Core,Angular2 Forms,我正在开发Angular 2应用程序,允许用户下载Word文档。现在它正在工作,但返回的名称是一个长字符串/GUID。我需要下载的文件的实际名称。以下是我们的设置: 在客户端: downloadWordTemplate(): void { this._data.getDocument(this.document.docKey) .subscribe(data => { const blob = new Blob([data], { type: 'application/vnd.

我正在开发Angular 2应用程序,允许用户下载Word文档。现在它正在工作,但返回的名称是一个长字符串/GUID。我需要下载的文件的实际名称。以下是我们的设置:

在客户端:

downloadWordTemplate(): void {
this._data.getDocument(this.document.docKey)
  .subscribe(data => {
    const blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' });
    const url = window.URL.createObjectURL(blob);
    const winObj = window.open(url);
    if (!winObj || winObj.closed || typeof winObj.closed === 'undefined') {
      this._toastr.info('File download blocked by pop-up blocker');
    }
  });
}
服务电话:

getDocument(docKey: string): Observable<any> {
    return this._http.get(`${this._env.systemApi}/Document/GetDocument/${docKey}`, { responseType: 'arraybuffer' });
}
getDocument(docKey:string):可观察


我继承了这一点,以前从未处理过Blob数据,所以有点卡住了

您可以在响应请求中设置带有文件名的标题

Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", FileName));

您可以在响应请求中使用文件名设置标题

Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", FileName));

我想出来了,需要补充:

Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");

到后端代码。

我想出来了,需要添加:

Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");

到后端代码。

Show
getDocument()
FGetDocument是后端代码Show
getDocument()
FGetDocument是后端代码,但它在AttachmentName中返回,我正试图弄清楚在它被传递到back后如何到达它,但它在AttachmentName中返回,我在想,一旦它被传回,我该怎么办