U Thu

U Thu

  • NA
  • 336
  • 22.2k

File Downlaod Problem in .net core

Nov 29 2017 5:16 AM
My project is DL project.This project store data and upload file.sql database of FileUploadPath is store upload file name.Upload progress is Ok.But download this DL PDF File progress is problem in now time.I would like to download link buttion click DL PDF Downloaded to Computer.This download file click action chtml is look like this
<td style="text-align:center">
@Html.DisplayFor(modelItem => item.Confirm.ApprovedStatus)&nbsp;<i class="glyphicon glyphicon-ok"></i>
</td>
<td>
<a asp-action="Download" asp-route-id="@item.ID" class="btn btn-link">Download</a>
</td>
<td class="hidden-print">
<a asp-action="Edit" asp-route-id="@item.ID" class="btn btn-primary"><i class="glyphicon glyphicon-pencil"></i>&nbsp;Edit</a> |
<a asp-action="Details" asp-route-id="@item.ID" class="btn btn-info"><i class="glyphicon glyphicon-book"></i>&nbsp;Details</a> |
<a asp-action="Delete" asp-route-id="@item.ID" class="btn btn-danger"><i class="glyphicon glyphicon-trash"></i>&nbsp;Delete</a>
</td> 
 
Nex this route is item.ID therefore Download Action is LookLike this
 
public FileResult Download(int id)
{
var Getfilename = _context.REHPData.FromSql("SELECT UploadFilePath" +
"FROM REHPData " +
"WHERE ID IN (@p0)", id);
string uploadpath = Path.Combine(_environment.WebRootPath, "UploadFiles");
var FilePath = Path.Combine(uploadpath, Getfilename.ToString());
return File(FilePath, "application/pdf");
 
}
 
This above action method using SELECT method.Really not using this style,I am using store procedure Below run application ID column is requierd present error
 
public FileResult Download(int id)
{
var parameter = new SqlParameter("@Id", id);
var Getfilename = _context.REHPData.FromSql("EXEC FileDownloadProcedure @Id", parameter).Single();
var filepath = Path.Combine(_environment.WebRootPath, "UploadFiles", filename.ToString()); 
return File(filepath, "application/pdf"); 
}

Please help me and code errror.
 
My sql StoreProcedure look like this :
 
CREATE PROCEDURE [dbo].[FileDownloadProcedure]
@param1 int
AS
SELECT UploadFilePath FROM DBO.REHPData WHERE ID= @param1
RETURN 0

 
 
 

Answers (2)