public ActionResult Download() { int FileId = Convert.ToInt32(TempData["FileId"]); try { int CurrentUserId = USerConfig.GetUserID(); if (objFileDataLayer.FileUserAccess(FileId, CurrentUserId)) { int RequestId = objFileDataLayer.GenerateRequest(FileId, CurrentUserId); List <int> PartnerIds = objFileDataLayer.GetPartnerIds(FileId); objFileDataLayer.GenerateOTP(PartnerIds, RequestId); string AccessStatus = objFileDataLayer.AuthorizeOTP(RequestId);//Until and unless we get NouserPending status the file will not download User_Controller userData = new User_Controller(); foreach (var partnerid in PartnerIds) { int GetOtp = userData.GetOtp(RequestId, partnerid); SMTPProtocol.NotifyPartners("Notification", string.Format("You partners is waiting for the file ,Please find the OTP : {0} .Use the following url to enter your ", GetOtp), userData.GetEmailbyPartnerId(partnerid.ToString())); } if (AccessStatus == "NoUserPending" && AccessStatus != "") { string fileName = objFileDataLayer.GetFileName(FileId); if (fileName != "NIL") { var filepath = Path.Combine(Server.MapPath("~/PostImage"), fileName); byte[] filedata = System.IO.File.ReadAllBytes(filepath); string contentType = MimeMapping.GetMimeMapping(filepath); var cd = new System.Net.Mime.ContentDisposition { FileName = fileName, Inline = true, }; Response.AppendHeader("Content-Disposition", cd.ToString()); objFileDataLayer.DeleteRequest(RequestId); return(File(filedata, contentType)); } else { ViewBag.Title = "File not found"; ViewBag.Message = "The file you are trying to access is deleted"; return(View()); } } else { return(View()); } } else { ViewBag.Title = "Illegal Entry"; ViewBag.Message = "You are not authorized to access this file"; return(View()); } } catch { return(View()); } }