Ejemplo n.º 1
0
        public H08(string Product)
        {
            try
            {
                Ftp.Client theFTP = new Ftp.Client("ftp://10.8.3.193", "admin", "123comparex");
                theFTP.ChangeWorkingDirectory("DVUGMS");
                theFTP.ChangeWorkingDirectory("SINOPTIC");
                theFTP.ChangeWorkingDirectory("H08");
                theFTP.ChangeWorkingDirectory(Product);

                string pathLast = theFTP.ListDirectory().Where(x => x.Substring(0, 3).Contains("cld")).OrderByDescending(x => x.ToLower()).First();

                string fileTemp = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".tmp";
                theFTP.DownloadFile(pathLast, fileTemp);


                using (Image image = Image.FromFile(fileTemp))
                {
                    using (MemoryStream m = new MemoryStream())
                    {
                        image.Save(m, image.RawFormat);
                        byte[] imageBytes = m.ToArray();

                        // Convert byte[] to Base64 String
                        string base64String = Convert.ToBase64String(imageBytes);
                        this.base64String = base64String;
                    }
                }
                System.IO.File.Delete(fileTemp);
            }
            catch (Exception ex)
            {
                this.base64String = ex.Message;
            }
        }
Ejemplo n.º 2
0
        public ActionResult Load(string Catalog)
        {
            List <String> theList = new List <String>();

            ViewBag.Catalog = Catalog;
            try
            {
                Ftp.Client theFTP = new Ftp.Client("ftp://10.8.3.193", "admin", "123comparex");
                theFTP.ChangeWorkingDirectory("DVUGMS");
                theFTP.ChangeWorkingDirectory("SINOPTIC");
                theFTP.ChangeWorkingDirectory("H08");
                theFTP.ChangeWorkingDirectory(Catalog);

                int i = 0;
                foreach (var item in theFTP.ListDirectory().Where(x => x.Substring(0, 3).Contains("cld")).OrderByDescending(x => x.ToLower()))
                {
                    i++;
                    if (i == 10)
                    {
                        break;
                    }
                    string fileTemp = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".tmp";
                    theFTP.DownloadFile(item, fileTemp);

                    using (Image image = Image.FromFile(fileTemp))
                    {
                        using (MemoryStream m = new MemoryStream())
                        {
                            image.Save(m, image.RawFormat);
                            byte[] imageBytes = m.ToArray();

                            // Convert byte[] to Base64 String
                            string base64String = Convert.ToBase64String(imageBytes);
                            theList.Add(base64String);
                        }
                    }
                    System.IO.File.Delete(fileTemp);
                }
                theList.Reverse();
            }
            catch (Exception er)
            {
                ViewBag.Error = er.Message;
            }

            return(View(theList));
        }