【问题标题】:Can I copy a image from Internet Explorer's cache loaded by WebBrowser?我可以从 WebBrowser 加载的 Internet Explorer 缓存中复制图像吗?
【发布时间】:2014-07-24 19:24:13
【问题描述】:

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

【问题讨论】:

  • 我不会依赖它——它是一个内部目录结构,随时可能被清除。
  • 甚至在我关闭使用 WebBrowser 的应用程序之前?
  • 是的。即可以设置自己的规则。
  • 不能强制删除吗?
  • 当然可以,但地毯可能会从你身边拉开。

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


【解决方案1】:

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);
            }
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-30
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    相关资源
    最近更新 更多