【发布时间】:2020-06-04 16:09:43
【问题描述】:
在我的 Internet Explorer 插件中,我想检测用户何时开始下载文件,我使用 FileDownload 事件但它不会;当用户下载文件但导航时不会触发。
为了说明情况,我创建了一个小型控制台应用程序(如果您想在您的计算机上测试它):
- 添加对
SHDocVwdll 的引用(位于C:\Windows\System32) - 使用以下代码创建控制台应用
- 如下文所述,让您的应用与 Internet Explorer 进行交互。
代码:
static void Main(string[] args)
{
SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer();
object Empty = 0;
object URL = "http://www.orimi.com/pdf-test.pdf";
IE.BeforeNavigate2 += WebBrowser_BeforeNavigate21;
IE.FileDownload += IE_FileDownload;
IE.Visible = true;
Thread.Sleep(60000);
IE.Quit();
}
public void OnBeforeNavigate2(object sender, ref object URL,
ref object Flags, ref object Target,
ref object PostData, ref object Headers,
ref bool Cancel)
{
Console.WriteLine("BeforeNavigate2 fired!");
}
private static void IE_FileDownload(bool ActiveDocument, ref bool Cancel)
{
Console.WriteLine($"{ActiveDocument} {DateTime.Now}");
Cancel = true;
}
启用 IE 与应用交互:
1.1 在内网资源管理器中打开“Internet 选项” 1.2取消选中“高级”选项卡下标记的复选框
【问题讨论】:
-
调试项目有没有报错?我发现你之前发过question。是同一个项目吗?我还发现another solution 使用javascript 来检测文件下载。如果可能,您也可以尝试一下。
-
@YuZhou 没有错误,如果是这样我会说。链接的解决方案假设我可以访问服务器端代码,这与扩展的情况不同。
-
我看到你问了几个类似的问题,我也回答了另一个问题。您可以查看我对this thread 的回答并加以考虑。我还建议您可以专注于一个线程,因为类似的线程会使我们感到困惑。
标签: c# windows internet-explorer add-on bho