There are word files and pdf files stored in a folder without extensions. When we open these files with pdf view or word viewer the corresponding files gets rendered. Now the requirement is to download these files from .net core application on click of the file name.
Below is the code sample:
public IActionResult Download(int Id)
{
var fileDetails = GetFileDetailsById(Id);
string fullpath = Path.Combine(_configuration.GetValue<string>("ServerPath:Documents:FolderPath"), FileNameWithoutExtension);
List<string> lines = new List<string>();
StreamReader reader = new StreamReader(fullpath);
while (!reader.EndOfStream)
{
lines.Add(reader.ReadLine());
}
byte[] dataAsBytes = lines.SelectMany(s => System.Text.Encoding.UTF8.GetBytes(s + Environment.NewLine)).ToArray();
var content = new System.IO.MemoryStream(dataAsBytes);
var contentType = ContentType; // Content ype saved in DB
var downloadFileName = OriginalFileName;// Original File Name saved in DB
return File(content, contentType, downloadFileName);
}
value of "fullpath" would be "\foldername\filename" without extension.
When the application is run, the files are downloaded without extension.
I would need help in downloading files with extension.