TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ahmed elbarbary
NA
1.6k
278k
How to download Excel template file from folder attachment using angul
Nov 22 2020 6:31 PM
I work on project angular 7 and web API asp.net core 2.2 I face issue I can't get Template Excel file
Exist on Server found on folder Attachment and file Name Delivery.xlsx to download it .
I only Need When click on download Button download Template Excel file from folder attachment
my issue How to get file Delivery.xlsx from attachment Folder and assign it on angular 7 to download ?
component.html
<input type=
"button"
class
=
"btn btn-success"
value=
"Download"
(click)=
"download()"
style=
"margin: 20px 0;"
/>
component.ts
download(file) {
let fileName = ???;
let checkFileType = fileName.split(
'.'
).pop();
var
fileType;
if
(checkFileType ==
".xlsx"
) {
fileType =
"application/vnd.openxmlformats officedocument.spreadsheetml.sheet"
;
}
this
.DownloadFile(fileName, fileType)
.subscribe(
success => {
saveAs(success, fileName);
},
err => {
alert(
"Server error while downloading file."
);
}
);
}
DownloadFile(filePath: string, fileType: string): Observable<any> {
let fileExtension = fileType;
let input = filePath;
return
this
.http.get(
'https://localhost:44396/api/ApprovalQuality/download'
+
"?fileName="
+ input, {
responseType:
'blob'
,
observe:
'response'
})
.pipe(
map((res: any) => {
return
new
Blob([res.body], { type: fileExtension });
})
);
}
Web API .net core 2.2
[HttpGet]
[Route(
"Download"
)]
public
IActionResult Download()
{
string
filename =
null
;
if
(filename ==
null
)
return
Content(
"filename not present"
);
var path = Path.Combine(
Directory.GetCurrentDirectory(),
"Attachment"
, filename);
var memory =
new
MemoryStream();
using
(var stream =
new
FileStream(path, FileMode.Open))
{
stream.CopyTo(memory);
}
memory.Position = 0;
ExcelEx ex =
new
ExcelEx();
return
File(memory, ex.GetContentType(path), Path.GetFileName(path));
}
Reply
Answers (
1
)
How to download Excel file to download path and open it on browser on
I get error property name when upload data ?