/// <summary>
        /// Simple wrapper function that downloads a url and returns a file path
        /// (uses all defaults, including writing the file to a temporary path)
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string Download(string url, int timeoutMs, WinInetCredentialsContext credentialsContext)
        {
            // do the download (will use cached images correctly, etc.)
            UrlDownloadToFile urlDownloadToFile = new UrlDownloadToFile();
            urlDownloadToFile.Url = url;
            urlDownloadToFile.TimeoutMs = timeoutMs;
            urlDownloadToFile.CredentialsContext = credentialsContext;
            urlDownloadToFile.Download();

            // return a bitmap based on the file
            return urlDownloadToFile.FilePath;
        }
        /// <summary>
        /// Simple wrapper function that downloads a url and returns a file path
        /// (uses all defaults, including writing the file to a temporary path)
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string Download(string url, int timeoutMs, WinInetCredentialsContext credentialsContext)
        {
            // do the download (will use cached images correctly, etc.)
            UrlDownloadToFile urlDownloadToFile = new UrlDownloadToFile();

            urlDownloadToFile.Url                = url;
            urlDownloadToFile.TimeoutMs          = timeoutMs;
            urlDownloadToFile.CredentialsContext = credentialsContext;
            urlDownloadToFile.Download();

            // return a bitmap based on the file
            return(urlDownloadToFile.FilePath);
        }
 public static Bitmap DownloadBitmap(string bitmapUrl, WinInetCredentialsContext credentialsContext)
 {
     // download the image
     try
     {
         string fileName = UrlDownloadToFile.Download(bitmapUrl, credentialsContext);
         return new Bitmap(fileName);
     }
     catch (Exception ex)
     {
         // reformat error for contextual clarity
         throw new Exception(
             String.Format(CultureInfo.CurrentCulture, "Error attempting to download bitmap from url {0}: {1}", bitmapUrl, ex.Message), ex);
     }
 }
        /// <summary>
        /// Constructs a new WebPageDownloader, permits script execution by default
        /// </summary>
        public WebPageDownloader(Control parentControl, WinInetCredentialsContext credentialsContext)
        {
            // create the undelrying control
            browserControl = new ExplorerBrowserControl();

            if (parentControl != null)
                browserControl.Parent = parentControl;

            browserControl.DownloadOptions = GetDownloadOptions();

            CredentialsContext = credentialsContext;

            // configure options
            browserControl.Silent = true;
        }
Example #5
0
 public static Bitmap DownloadBitmap(string bitmapUrl, WinInetCredentialsContext credentialsContext)
 {
     // download the image
     try
     {
         string fileName = UrlDownloadToFile.Download(bitmapUrl, credentialsContext);
         return(new Bitmap(fileName));
     }
     catch (Exception ex)
     {
         // reformat error for contextual clarity
         throw new Exception(
                   String.Format(CultureInfo.CurrentCulture, "Error attempting to download bitmap from url {0}: {1}", bitmapUrl, ex.Message), ex);
     }
 }
Example #6
0
        /// <summary>
        /// Constructs a new WebPageDownloader, permits script execution by default
        /// </summary>
        public WebPageDownloader(Control parentControl, WinInetCredentialsContext credentialsContext)
        {
            // create the undelrying control
            browserControl = new ExplorerBrowserControl();

            if (parentControl != null)
            {
                browserControl.Parent = parentControl;
            }

            browserControl.DownloadOptions = GetDownloadOptions();

            CredentialsContext = credentialsContext;

            // configure options
            browserControl.Silent = true;
        }
        public BrowserMiniForm(string url, int downloadOptions, WinInetCredentialsContext credentialsContext)
        {
            // record url to navigate to
            _url = url;

            // standard "flyout" form behavior
            DismissOnDeactivate = true;

            // dock inset for drawing of border
            DockPadding.All = 1;

            // background color is white to minimize flashing problem when dismissing
            BackColor = Color.White;

            // initialize browser control
            _explorerBrowserControl = new ExplorerBrowserControl();
            _explorerBrowserControl.Dock = DockStyle.Fill;
            Controls.Add(_explorerBrowserControl);

            // install download options if requested
            if (downloadOptions > 0)
            {
                _explorerBrowserControl.DownloadOptions = downloadOptions;
            }

            // install network credential if requested
            if (credentialsContext != null)
            {
                if (credentialsContext.NetworkCredential != null)
                    _explorerBrowserControl.NetworkCredential = credentialsContext.NetworkCredential;

                if (credentialsContext.CookieString != null)
                    _explorerBrowserControl.SetCookies(credentialsContext.CookieString.Url, credentialsContext.CookieString.Cookies);
            }

            // other options
            _explorerBrowserControl.Silent = true;

            // Navigate to about:blank for installation of ui customizations. Note that this step is CRITICAL
            // to ensuring that not only our custom ui hooks get installed but also to ensure that our DLCTL
            // options (which control security) are registered prior to the fectching of the content.
            _explorerBrowserControl.DocumentComplete += new BrowserDocumentEventHandler(_explorerBrowserControl_AboutBlankDocumentComplete);
            _explorerBrowserControl.Navigate("about:blank");
        }
 public static string Download(string url, WinInetCredentialsContext credentialsContext)
 {
     return(Download(url, NO_TIMEOUT, credentialsContext));
 }
 public static string Download(string url, WinInetCredentialsContext credentialsContext)
 {
     return Download(url, NO_TIMEOUT, credentialsContext);
 }