Inheritance: INotifyPropertyChanging, INotifyPropertyChanged
Ejemplo n.º 1
0
        public static FT.DB.Image GetNewImage(string url)
        {
            int BufferLength = 1024;
            try
            {
                WebRequest r = WebRequest.Create(url);
                HttpWebResponse resp = (HttpWebResponse)r.GetResponse();

                FT.DB.Image img = new FT.DB.Image();

                Stream s = resp.GetResponseStream(); //Source
                MemoryStream ms = new MemoryStream((int)resp.ContentLength); //Destination

                // from http://www.xtremevbtalk.com/showthread.php?t=263275
                byte[] b = new byte[BufferLength]; //Buffer
                int cnt = 0;
                do
                {
                    cnt = s.Read(b, 0, BufferLength);
                    //Write the number of bytes actually read
                    ms.Write(b, 0, cnt);
                }
                while (cnt > 0);

                Binary bin = new Binary(ms.ToArray());
                img.Data = bin;
                img.ContentType = resp.ContentType;
                return img;
            }

            catch (Exception ex)
            {
                Console.WriteLine("Exception caught, trying to fetch: " + url + " - Exception: " + ex.ToString());
                return null;
            }
        }