Here i am trying to open the file of any extension format in ASP.NET MVC CORE 2.0
that has been saved in data base according to the extension format of that file without downloading that file. For example lets say i have ms word file so when i click that file it should open in word, if i have pdf it should open in pdf format without downloading the file.
Now, the problem in my code is that it force to download the file instead of opening the file according to respective file extemsion format.
Any help will be a great and will be thank full.Thank You
Below is my code
public IActionResult ViewFileByFileId (int id)
{
DoctorCredentialDocsModel DoctorCredential = new DoctorCredentialDocsModel();
DoctorCredential = _doctorService.GetDoctorCredentialDetails(id);
string AttachPath = ConfigPath.DoctorCredentialsAttachmentPath;
string strFileFullPath = Path.Combine(AttachPath, DoctorCredential.AttachedFile);
string contentType = MimeTypes.GetMimeType(strFileFullPath);
if (!strFileFullPath.Contains("..\\"))
{
byte[] filedata = System.IO.File.ReadAllBytes(strFileFullPath);
var cd = new System.Net.Mime.ContentDisposition
{
FileName = DoctorCredential.FileName,
Inline = false,
};
Request.HttpContext.Response.Headers.Add("Content-Disposition", cd.ToString());
return File(filedata, contentType);
}
else
{
return new NotFoundResult();
}
}