public HttpResponseMessage ZipPolicyCovidNotCer([FromBody] object _Reqbody) { HttpResponseMessage _response = new HttpResponseMessage(); byte[] Resulte = null; try { string inJson = ""; ObjConvertJson(ref inJson, _Reqbody); DataTable _dt = JsonConvert.DeserializeObject <DataTable>(inJson); if (_dt.Rows.Count > 1) { string _Fliename = "CVP" + DateTime.Now.ToString("ddMMyyyHHmmss") + ".zip"; string FileOutPut = RootPathFilePolCovid + _Fliename; ZipFile MyZip; MyZip = ZipFile.Create(FileOutPut); MyZip.BeginUpdate(); foreach (DataRow _dr in _dt.Rows) { string Path = _dr["physical_path"].ToString() , Filename = _dr["policy_no"].ToString() + ".pdf"; MyZip.Add(Path, Filename); } MyZip.CommitUpdate(); MyZip.Close(); Resulte = File.ReadAllBytes(FileOutPut); File.Delete(FileOutPut); } else { foreach (DataRow _dr in _dt.Rows) { string Path = _dr["physical_path"].ToString() , Filename = _dr["policy_no"].ToString() + ".pdf"; Resulte = File.ReadAllBytes(Path); } } _response.StatusCode = HttpStatusCode.OK; } catch (Exception ex) { _response.StatusCode = HttpStatusCode.InternalServerError; } _response.Content = new ObjectContent(Resulte.GetType(), Resulte, new JsonMediaTypeFormatter()); return(_response); }
public HttpResponseMessage ZipPolicyCovid([FromBody] DataTable _Reqbody) { HttpResponseMessage _response = new HttpResponseMessage(); byte[] Resulte = null; string FileResulte = ""; string _type = ""; try { DataTable _dt = _Reqbody; if (_dt.Rows.Count > 1) { string _Fliename = "CVP" + DateTime.Now.ToString("ddMMyyyHHmmssfff") + ".zip"; string FileOutPut = RootPathFilePolCovid + _Fliename; ZipFile MyZip; MyZip = ZipFile.Create(FileOutPut); try { MyZip.BeginUpdate(); foreach (DataRow _dr in _dt.Rows) { string Path = _dr["physical_path"].ToString() , Filename = _dr["policy_no"].ToString() + ".pdf"; MyZip.Add(Path, Filename); } MyZip.CommitUpdate(); MyZip.Close(); Resulte = File.ReadAllBytes(FileOutPut); _type = MimeMapping.GetMimeMapping(Path.GetExtension(FileResulte)); File.Delete(FileOutPut); } catch (Exception) { _response.StatusCode = HttpStatusCode.InternalServerError; } finally { if (MyZip != null) { MyZip.Close(); } } } else { foreach (DataRow _dr in _dt.Rows) { string _Path = _dr["physical_path"].ToString() , Filename = _dr["policy_no"].ToString() + ".pdf"; FileResulte = _Path; _type = MimeMapping.GetMimeMapping(Path.GetExtension(FileResulte)); Resulte = File.ReadAllBytes(FileResulte); } } _response.StatusCode = HttpStatusCode.OK; _response.Content = new ByteArrayContent(Resulte); _response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(_type); } catch (Exception ex) { _response.StatusCode = HttpStatusCode.InternalServerError; } return(_response); }