public void DownloadARReport(string fileLocationURL)
        {
            try
            {
                string baseurl = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Host, ConfigurationManager.AppSettings["AtlasBaseURL"]);
                byte[] data    = Http.Get <byte[]>(string.Format("{0}/{1}", baseurl, fileLocationURL), CookieHelper.CookiesContainer);

                String[] urlParts   = fileLocationURL.Split('/');
                string   reportName = urlParts[2];
                DateTime reportDate = DateTime.Now;
                DateTime.TryParse(urlParts[3], out reportDate);

                string ext = ".pdf";

                HttpResponse response = System.Web.HttpContext.Current.Response;
                response.Clear();
                response.ClearContent();
                response.ClearHeaders();

                response.ContentType = DocumentManagementMimeType.GetMIMETypeByFileExtenstion(ext);
                response.AddHeader("Content-Disposition", "attachment; filename=\"" + reportName + '-' + reportDate.ToString("MMM-YYYY") + "-" + ext + "\"");
                response.AddHeader("Content-Length", data.Length.ToString());
                response.AddHeader("Content-Description", "File Transfer");
                response.AddHeader("Content-Transfer-Encoding", "binary");

                if (!response.Cookies.AllKeys.Contains("fileDownload"))
                {
                    response.Cookies.Add(new HttpCookie("fileDownload", "true"));
                }

                response.BinaryWrite(data);
                response.Flush();
            }
            catch { }
        }
        /// <summary>
        /// Downloads the document
        /// </summary>
        /// <param name="fileLocationURL">fileLocationURL</param>
        public void DownloadDocumentFromUrl(string fileLocationURL)
        {
            String[] fullDocName = fileLocationURL.Split('\\');

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fileLocationURL);

            request.CookieContainer = CookieHelper.CookiesContainer;
            byte[] data = null;

            if (request != null)
            {
                // Send the request to the server and retrieve the
                // WebResponse object
                WebResponse fileResponse = request.GetResponse();
                if (fileResponse != null)
                {
                    Stream       respStream = fileResponse.GetResponseStream();
                    MemoryStream memStream  = new MemoryStream();
                    byte[]       buffer     = new byte[2048];

                    int bytesRead = 0;
                    do
                    {
                        bytesRead = respStream.Read(buffer, 0, buffer.Length);
                        memStream.Write(buffer, 0, bytesRead);
                    } while (bytesRead != 0);

                    respStream.Close();

                    data = memStream.ToArray();
                }
            }

            HttpResponse response = System.Web.HttpContext.Current.Response;

            response.Clear();
            response.ClearContent();
            response.ClearHeaders();
            response.ContentType = DocumentManagementMimeType.GetMIMETypeByFileExtenstion(fileLocationURL);             //
            response.AddHeader("Content-Disposition", "attachment; filename=\"" + fullDocName[fullDocName.Length - 1] + "\"");
            response.AddHeader("Content-Length", data.Length.ToString());
            response.AddHeader("Content-Description", "File Transfer");
            response.AddHeader("Content-Transfer-Encoding", "binary");
            if (!response.Cookies.AllKeys.Contains("fileDownload"))
            {
                response.Cookies.Add(new HttpCookie("fileDownload", "true"));
            }
            response.BinaryWrite(data);
            response.Flush();
        }
 /// <summary>
 /// To Open a File in Browser
 /// </summary>
 /// <param name="fileLocationURL">fileLocationURL</param>
 /// <changeHistory>
 /// <id>DE22054</id> <by>Vasanthakumar</by> <date>08-03-2016</date> <description>User cant view/download the uploaded documents for Truckload Carriers in Carrier > Mapping</description>
 /// </changeHistory>
 public void OpenCarrierMappingFromDocumentManagement(string fileLocationURL)
 {
     try
     {
         //// ###START: DE22054
         string baseurl = ConfigurationManager.AppSettings["DocumentManagement"];
         ////string baseurl = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Host, ConfigurationManager.AppSettings["AtlasBaseURL"]);
         //// ###END: DE22054
         var          dataAtlas          = Http.Get <Documents>(string.Format("{0}/{1}", baseurl, fileLocationURL), CookieHelper.CookiesContainer, "application/json");
         string       contentDisposition = string.Format("inline; filename=\"{0}\"", dataAtlas.FileRelativePath);
         HttpResponse response           = System.Web.HttpContext.Current.Response;
         response.ContentType = DocumentManagementMimeType.GetMIMETypeByFileExtenstion(dataAtlas.FileExtension);
         response.AddHeader("Content-Disposition", contentDisposition);
         response.AddHeader("Content-Length", dataAtlas.FileContent.Length.ToString());
         response.AddHeader("Content-Description", "File Transfer");
         response.AddHeader("Content-Transfer-Encoding", "binary");
         response.BinaryWrite(dataAtlas.FileContent);
     }
     catch
     {
         Response.Write("File Not found");
     }
 }
        public void DownloadReportFromDocumnetManagment(string fileRelativePath)
        {
            try
            {
                ////### Start DE21231
                //string baseurl = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Host, ConfigurationManager.AppSettings["AtlasBaseURL"]);

                string baseurl = ConfigurationManager.AppSettings["DocumentManagement"];

                //string baseAtlasURL = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Host, ConfigurationManager.AppSettings["AtlasBaseURL"]);

                ////### End DE21231
                //// ###START: US19934
                var dataAtlas = Http.Get <Documents>(string.Format("{0}/{1}", baseurl, "//GetDocumentsInBytes//?fileRelativePath=" + fileRelativePath), CookieHelper.CookiesContainerInternal, "application/json");
                //// ###END: US19934
                var fileName = Path.GetFileName(fileRelativePath);

                HttpResponse response = System.Web.HttpContext.Current.Response;
                response.ContentType = DocumentManagementMimeType.GetMIMETypeByFileExtenstion(".xls");
                response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "");
                response.AddHeader("Content-Length", dataAtlas.FileContent.Length.ToString());
                response.AddHeader("Content-Description", "File Transfer");
                response.AddHeader("Content-Transfer-Encoding", "binary");

                if (!response.Cookies.AllKeys.Contains("fileDownload"))
                {
                    response.Cookies.Add(new HttpCookie("fileDownload", "true"));
                }

                response.BinaryWrite(dataAtlas.FileContent);
                response.Flush();
                response.End();
            }
            catch (Exception ex)
            {
            }
        }
        public void DownloadReport(string reportURL, string chartData)
        {
            try
            {
                chartData = HttpUtility.HtmlDecode(chartData);
                byte[] data = null;

                String[] urlParts   = reportURL.ToString().Split('/');
                string   reportName = urlParts[2];
                string   reportType = urlParts[3];

                if (string.IsNullOrEmpty(chartData))
                {
                    string baseurl = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Host, ConfigurationManager.AppSettings["AtlasBaseURL"]);
                    data = Http.Get <byte[]>(string.Format("{0}/{1}", baseurl, reportURL), CookieHelper.CookiesContainer);
                }
                else
                {
                    dynamic parameters = new ExpandoObject();
                    parameters.ExportType    = reportType;
                    parameters.SortingColumn = urlParts[4];
                    parameters.SortingOrder  = urlParts[5];
                    parameters.FilterType    = urlParts[6];
                    parameters.FromDate      = urlParts[7];
                    string[] queryString = urlParts[8].Split('?');
                    parameters.ToDate = queryString[0];

                    if (queryString.Length > 1)
                    {
                        parameters.CurrentTimestamp = queryString[1].Split('=')[1];
                    }

                    parameters.ChartData = HttpUtility.UrlDecode(chartData);

                    string baseurl  = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Host, ConfigurationManager.AppSettings["AtlasBaseURL"]);
                    string atlasUrl = string.Format("{0}/{1}/{2}", urlParts[0], urlParts[1], urlParts[2]);

                    data = Http.Post <byte[]>(string.Format("{0}/{1}", baseurl, atlasUrl), parameters, "application/json", "application/json", CookieHelper.CookiesContainer);
                }

                string ext = ".txt";
                switch (reportType)
                {
                case "EXCEL":
                    ext = ".xls";
                    break;

                case "PDF":
                    ext = ".pdf";
                    break;

                case "CSV":
                    ext = ".csv";
                    break;
                }

                HttpResponse response = System.Web.HttpContext.Current.Response;

                response.Clear();
                response.ClearContent();
                response.ClearHeaders();

                response.ContentType = DocumentManagementMimeType.GetMIMETypeByFileExtenstion(ext);
                response.AddHeader("Content-Disposition", "attachment; filename=\"" + reportName + ext + "\"");
                response.AddHeader("Content-Length", data.Length.ToString());
                response.AddHeader("Content-Description", "File Transfer");
                response.AddHeader("Content-Transfer-Encoding", "binary");

                if (!response.Cookies.AllKeys.Contains("fileDownload"))
                {
                    response.Cookies.Add(new HttpCookie("fileDownload", "true"));
                }
                response.BinaryWrite(data);
                response.Flush();
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }