我可以从WebBrowser加载的Internet Explorer缓存中复制图像吗?

时间:2014-07-24 19:24:14

标签: c# image internet-explorer browser temporary-files

我读过如果我在webBrowser中显示了一个图像,那么我已经下载了它,所以我可以从Internet Explorer tmp文件中获取它。它甚至可能吗?若然,任何C#代码示例如何做tgis?我查看了Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)文件夹,但我找不到任何图片。不确定它是否是正确的道路。它可以节省大量时间,只需下载一次图像。

1 个答案:

答案 0 :(得分:2)

请参阅c# - Programmatically Copy Files from 'Temporary Internet Files' into other directory - Stack Overflow

以下示例代码

        //see https://stackoverflow.com/questions/19581094/programmatically-copy-files-from-temporary-internet-files-into-other-directory
        var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache), "Content.IE5");
        string[] files = Directory.GetFiles(path, "*", SearchOption.AllDirectories);   
        HashSet<string> extensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
        extensions.Add(".ico");
        extensions.Add(".jpg");
        extensions.Add(".jpeg");
        extensions.Add(".png");
        extensions.Add(".gif");
        extensions.Add(".bmp");

        string DestinationFolder2Copyfiles = @"e:\images\";
        HashSet<string> alreadyCopiedFilesHolder = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
        foreach (string f in files)
        {
            string ext = System.IO.Path.GetExtension(f);
            if (extensions.Contains(ext))
            {
                string destFileName = Path.Combine(DestinationFolder2Copyfiles, Path.GetFileName(f));
                int i = 0;
                while (alreadyCopiedFilesHolder.Contains(destFileName) || System.IO.File.Exists(destFileName))
                {
                    destFileName = Path.Combine(DestinationFolder2Copyfiles, string.Format("{0}_{1}{2}", Path.GetFileNameWithoutExtension(f), i, ext));
                    i += 1;
                }
                alreadyCopiedFilesHolder.Add(destFileName);
                System.IO.File.Copy(f, destFileName);
            }
        }