I have done the function to save a file to a Folder in Server, **I am now trying to get the file back from Server by using HTML download
, but haven't found the way to get the correct filepath yet.
After stored a file in a Folder in Server, saved filePath in DB by using Entity Framework, I retrieved file
from DB with filePath = /VisitReportAttachments/1ea2b64e-545d-4c50-ae7d-eefa7178d310.png
. But this filePath doesn't work right.
<a href="@file.Path" download="@file.name">Click here to download</a>
//file.Path = /VisitReportAttachments/1ea2b64e-545d-4c50-ae7d-eefa7178d310.png
I got an error: Failed - No file
Take a look at create FilePath path
in SaveFile code in Controller:
private void SaveFile(HttpPostedFileBase file)
{
string serverPath = "\\VisitReportAttachments";
if (file!= null)
{
if (!Directory.Exists(serverPath))
{
Directory.CreateDirectory(serverPath);
}
var fileName = Guid.NewGuid()+ Path.GetExtension(file.FileName);
var path = Path.Combine("\\", new DirectoryInfo(serverPath).Name, fileName);
path = relativePath.Replace(@"\", "/"); //this path is stored to DB
....
//As I mentioned: save file to Server is done. I simply post the code that create the filepath in SQL DB while file is storing to Server*
}
}
FilePath is stored in DB like: /VisitReportAttachments/1ea2b64e-545d-4c50-ae7d-eefa7178d310.png
Need help!