Example #1
0
 /// <summary>
 /// Gets url of the image
 /// </summary>
 /// <returns>Url if found and null otherwise</returns>
 private string GetUrl()
 {
     try
     {
         if (context.IsEmpty() | contextURL.IsEmpty())
         {
             return(null);
         }
         string     ctx = context.ToLower();
         WebRequest req = WebRequest.Create(contextURL);
         req.Timeout = 10000;
         WebResponse          rs     = req.GetResponse();
         System.IO.TextReader reader = new System.IO.StreamReader(rs.GetResponseStream());
         IEnumerable <string> en     = reader.ToEnumerable();
         foreach (string str in en)
         {
             string ss  = str.ToLower();
             string url = str + "";
             // If string contains context
             if (str.ToLower().Contains(ctx))
             {
                 int n = ss.IndexOf(ctx);
                 url = url.Substring(n);
                 ss  = ss.Substring(n);
                 n   = ss.IndexOf("src");
                 url = url.Substring(n);
                 ss  = ss.Substring(n);
                 n   = ss.IndexOf("\"") + 1;
                 url = url.Substring(n);
                 ss  = ss.Substring(n);
                 n   = ss.IndexOf("\"");
                 url = url.Substring(0, n);
                 ss  = ss.Substring(0, n);
                 if (!ss.Contains("http:"))
                 {
                     string bb = contextURL.Substring(0, contextURL.LastIndexOf("/") + 1);
                     url = bb + url;
                 }
                 // Returns url
                 return(url);
             }
         }
         // Returns null
         return(null);
     }
     catch (Exception ex)
     {
         // Error indication
         ex.ShowError();
     }
     return(null);
 }