public HttpResponseMessage OpenFileForEservice([FromBody] OpenDocumentParams data) { return(new HttpResponseMessage() { Content = new StringContent(MobileDataBase.DownloadOrgReqDocForEservice(data), System.Text.Encoding.UTF8, "application/json") }); }
public HttpResponseMessage OpenFile([FromBody] OpenDocumentParams data) { string login = ConfigurationManager.AppSettings["UploadAccessUserId"].ToString(); string domain = ConfigurationManager.AppSettings["UploadAccessDomainName"].ToString(); string password = Crypt.DecryptData(ConfigurationManager.AppSettings["UploadAccessPassword"].ToString()); string tokenId = (data == null || data.tokenId == null) ? "" : data.tokenId; string mUserid = (data == null || data.mUserid == null) ? "" : data.mUserid; string DocumentId = (data == null || data.DocumentId == null) ? "" : data.DocumentId; //tokenId = Convert.ToString(System.Web.HttpContext.Current.Request.Form["tokenId"]); //mUserid = Convert.ToString(System.Web.HttpContext.Current.Request.Form["mUserid"]); //DocumentId = Convert.ToString(System.Web.HttpContext.Current.Request.Form["DocumentId"]); MobileDataBase.Result rslt = MobileDataBase.GetValidUserDetails(tokenId, mUserid); rslt.Data = null; try { if (rslt.status == "0") { string SuffixPath = MobileDataBase.GetDocPath(DocumentId, mUserid); string sPath = ""; sPath = Path.Combine(ServerUploadFolder, SuffixPath); if (ConfigurationManager.AppSettings["UploadAccessImpersinationRequired"].ToString() == "Y") { using (UserImpersonation user = new UserImpersonation(login, domain, password)) { if (user.ImpersonateValidUser()) { return(DownLoadFile(sPath)); } } } else { return(DownLoadFile(sPath)); } } } catch (Exception ex) { throw ex; } return(this.Request.CreateResponse(HttpStatusCode.NotFound, "File not found.")); }
private MobileDataBase.Result UploadFile(MobileDataBase.Result rslt, string DocumentName, string DocumentType, string OrgReqId, string OrgId, bool ImportLicenseDoc, string LicenseNumber, string IssuanceDate, string ExpiryDate, string LicenseType) { MobileDataBase m = new MobileDataBase(); string ID = m.GetNewIntKey("ScanRequestUploadDocs"); string sPath = ""; string UploadedFrom = Convert.ToString(System.Web.HttpContext.Current.Request.Form["UploadedFrom"]); string ShareFolderPath1 = Path.Combine(UploadedFrom, DateTime.Now.Year + "\\" + DateTime.Now.Month.ToString("00") + "\\" + DateTime.Now.Day.ToString("00") + '\\' + OrgReqId + '\\' + ID);// System.Web.Hosting.HostingEnvironment.MapPath("~/locker/"); sPath = Path.Combine(UploadedFrom, DateTime.Now.Year + "\\" + DateTime.Now.Month.ToString("00") + "\\" + DateTime.Now.Day.ToString("00") + '\\' + OrgReqId + '\\' + ID); // System.Web.Hosting.HostingEnvironment.MapPath("~/locker/"); // sPath = Path.Combine("Etrade\\" + UploadedFrom, DateTime.Now.Year + "\\" + DateTime.Now.Month.ToString("00") + "\\" + DateTime.Now.Day.ToString("00") + '\\' + OrgReqId + '\\' + ID);// System.Web.Hosting.HostingEnvironment.MapPath("~/locker/"); // string ShareFolderPath1 = UploadedFrom + "\\" + year + "\\" + month + "\\" + day + "\\" + sProfileReferenceId;// +DeclarationId; System.Web.HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files; FileResult Frdata = new FileResult(); Frdata.DocumentName = DocumentName; Frdata.DocumentType = DocumentType; Frdata.OrgReqId = OrgReqId; Frdata.UploadedFrom = Convert.ToString(System.Web.HttpContext.Current.Request.Form["UploadedFrom"]); // Frdata.NewFileName = DocumentName; Frdata.FilePath = DateTime.Now.Year + "\\" + DateTime.Now.Month.ToString("00") + "\\" + DateTime.Now.Day.ToString("00") + '\\' + OrgReqId; Frdata.IsUploaded = 'n'; if (System.Web.HttpContext.Current.Request.Form["eservicerequestid"] != null) { Frdata.EserviceRequestId = Convert.ToString(System.Web.HttpContext.Current.Request.Form["eservicerequestid"]); if (!Convert.ToString(System.Web.HttpContext.Current.Request.Form["eservicerequestid"]).All(char.IsDigit)) { Frdata.EserviceRequestId = CommonFunctions.CsUploadDecrypt(Convert.ToString(System.Web.HttpContext.Current.Request.Form["eservicerequestid"]).ToString()); } } // CHECK THE FILE COUNT. FileInfo F = null; for (int iCnt = 0; iCnt <= hfc.Count - 1; iCnt++) { System.Web.HttpPostedFile hpf = hfc[iCnt]; if (hpf.ContentLength > 0) { try { int iLen = hpf.ContentLength; byte[] btArr = new byte[iLen]; hpf.InputStream.Read(btArr, 0, iLen); var memoryStream = new MemoryStream(btArr); Boolean isValidFile = false; if (hpf.ContentType.Contains("image")) { isValidFile = IsImage(memoryStream); } else if (hpf.ContentType.Contains("application/pdf")) { isValidFile = IsPDF(memoryStream); } if (isValidFile) { if (!Directory.Exists(Path.Combine(ServerUploadFolder, ShareFolderPath1))) { Directory.CreateDirectory(Path.Combine(ServerUploadFolder, ShareFolderPath1)); } // sPath = ShareFolderPath1 + "\\" + FullfileName; // file.SaveAs(Path.Combine(ServerUploadFolder, sPath)); // CHECK IF THE SELECTED FILE(S) ALREADY EXISTS IN FOLDER. (AVOID DUPLICATE) // if (!File.Exists(Path.Combine(sPath, Path.GetFileName(hpf.FileName))) && Regex.IsMatch(hpf.FileName.Trim(), "(\\.(jpg|jpeg|pdf))$", RegexOptions.IgnoreCase)) { // SAVE THE FILES IN THE FOLDER. string NewfileName; string extension = Path.GetExtension(hpf.FileName); if (UploadedFrom == "OrganizationRequests") { NewfileName = DocumentName;//+ extension; } else { NewfileName = DocumentName + extension; } NewfileName = NewfileName.Replace('/', '-'); Frdata.NewFileName = NewfileName; // hpf.SaveAs(Path.Combine(sPath, Path.GetFileName(hpf.FileName))); hpf.SaveAs(Path.Combine(ServerUploadFolder, sPath, NewfileName)); Frdata.Name = Path.Combine(sPath, NewfileName); Frdata.FilePath = Path.Combine(sPath, NewfileName); // F = new FileInfo(Path.Combine(sPath, Path.GetFileName(hpf.FileName))); F = new FileInfo(Path.Combine(ServerUploadFolder, sPath, NewfileName)); Frdata.FileSize = (F.Length / 1024).ToString("0.00"); Frdata.IsUploaded = 'y'; break; } } } catch (Exception ex) { using (System.IO.StreamWriter file = new System.IO.StreamWriter(System.Web.HttpContext.Current.Server.MapPath("~/logEmail.txt"), true)) { file.WriteLine(ex.ToString()); file.Close(); } } } } if (Frdata.IsUploaded == 'y') { rslt.Data = MobileDataBase.UpdateUploadDataDS(rslt.mUserId, Frdata, OrgId, ImportLicenseDoc, LicenseNumber, IssuanceDate, ExpiryDate, LicenseType); // if (F != null) // { // F.Rename(Frdata.NewFileName); //} } return(rslt); }
public ActionResponse Upload(string Domain, string UserId, string Password, ) { //string login = ConfigurationManager.AppSettings["UploadAccessUserId"].ToString(); //string domain = ConfigurationManager.AppSettings["UploadAccessDomainName"].ToString(); //string password = Crypt.DecryptData(ConfigurationManager.AppSettings["UploadAccessPassword"].ToString()); //<add key="UploadAccessImpersinationRequired" value="Y" /> //<add key="UploadAccessUserId" value="SVC_CSMaqasaDocnew" /> //<add key="UploadAccessDomainName" value="KGACHQ" /> //<add key="UploadAccessPassword" value="MKjuOI9MZWxxD/StmFdCWqOCX+bngatC" /> //string tokenId = ""; //string mUserid = ""; //string OrgReqId = "", OrgId = ""; //string DocumentName = ""; //string DocumentType = ""; //string eservicerequestid = ""; //bool ImportLicenseDoc = false;////added newly - to differentiate if the upload is for Importer license details //string LicenseNumber = "", IssuanceDate = "", ExpiryDate = "", LicenseType = "";//added newly - form data passed in ajax request //tokenId = Convert.ToString(System.Web.HttpContext.Current.Request.Form["tokenId"]); //mUserid = Convert.ToString(System.Web.HttpContext.Current.Request.Form["mUserid"]); //DocumentName = Convert.ToString(System.Web.HttpContext.Current.Request.Form["DocumentName"]); //DocumentType = Convert.ToString(System.Web.HttpContext.Current.Request.Form["DocumentType"]); //ImportLicenseDoc = Convert.ToBoolean(System.Web.HttpContext.Current.Request.Form["ImportLicenseDoc"]); //string UploadedFrom = Convert.ToString(System.Web.HttpContext.Current.Request.Form["UploadedFrom"]); //eservicerequestid = Convert.ToString(System.Web.HttpContext.Current.Request.Form["eservicerequestid"]); //OrgReqId = Convert.ToString(System.Web.HttpContext.Current.Request.Form["OrgReqId"]); //OrgId = Convert.ToString(System.Web.HttpContext.Current.Request.Form["OrgId"]); if (eservicerequestid != null) { if (!eservicerequestid.All(char.IsDigit)) { eservicerequestid = CommonFunctions.CsUploadDecrypt(eservicerequestid.ToString()); } } if (!OrgReqId.All(char.IsDigit)) { OrgReqId = CommonFunctions.CsUploadDecrypt(OrgReqId.ToString()); } if (!DocumentType.All(char.IsDigit)) { DocumentType = CommonFunctions.CsUploadDecrypt(DocumentType); } MobileDataBase.Result rslt = new MobileDataBase.Result(); if (UploadedFrom != "BRSExamDOCS") { rslt = MobileDataBase.GetValidUserDetails(tokenId, mUserid); rslt.Data = null; } { rslt.status = "0"; } try { // rslt.status = "0"; if (rslt.status == "0") { if (ImportLicenseDoc)//added newly // to differentiate if the upload is for Importer license details { LicenseNumber = Convert.ToString(System.Web.HttpContext.Current.Request.Form["LicenseNumber"]); IssuanceDate = Convert.ToString(System.Web.HttpContext.Current.Request.Form["IssuanceDate"]); ExpiryDate = Convert.ToString(System.Web.HttpContext.Current.Request.Form["ExpiryDate"]); LicenseType = Convert.ToString(System.Web.HttpContext.Current.Request.Form["LicenseType"]); string StatusCode = MobileDataBase.UniqueImporterLicenseCheck(LicenseNumber, OrgReqId, OrgId); if (StatusCode == "-1") { rslt.status = "-11"; return(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(rslt, Formatting.None)//Frdata , System.Text.Encoding.UTF8, "application/json") }); } } if (ConfigurationManager.AppSettings["UploadAccessImpersinationRequired"].ToString() == "Y") { using (UserImpersonation user = new UserImpersonation(UserId, Domain, Password)) { if (user.ImpersonateValidUser()) { UploadFile(rslt, DocumentName, DocumentType, OrgReqId, OrgId, ImportLicenseDoc, LicenseNumber, IssuanceDate, ExpiryDate, LicenseType); } else { throw new UnauthorizedAccessException("Access failed while uploading."); } } } else { UploadFile(rslt, DocumentName, DocumentType, OrgReqId, OrgId, ImportLicenseDoc, LicenseNumber, IssuanceDate, ExpiryDate, LicenseType); } } } catch (Exception ex) { throw ex; } return(new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(rslt, Formatting.None)//Frdata , System.Text.Encoding.UTF8, "application/json") }); }