首页 新闻 会员 周边

c#中实现IDownloadManager接口的问题?

0
悬赏园豆:10 [已关闭问题] 关闭于 2013-11-27 21:24
从网上找到一段实现了此接口的代码,可以接管IE的下载,代码如下:
public int Download(IMoniker pmk, IBindCtx pbc, uint dwBindVerb, int grfBINDF, 
            IntPtr pBindInfo, string pszHeaders, string pszRedir, uint uiCP)
        {

            // Get the display name of the pointer to an IMoniker interface that specifies
            // the object to be downloaded.
            string name = string.Empty;
            pmk.GetDisplayName(pbc, null, out name);

            if (!string.IsNullOrEmpty(name))
            {
                Uri url = null;
                bool result = Uri.TryCreate(name, UriKind.Absolute, out url);

                if (result)
                {

                    // Launch CSWebDownloader.exe to download the file. 
                    FileInfo assemblyFile =
                        new FileInfo(Assembly.GetExecutingAssembly().Location);
                    ProcessStartInfo start = new ProcessStartInfo
                    {
                        Arguments = name,
                        FileName =
                        string.Format("{0}\\CSWebDownloader.exe", assemblyFile.DirectoryName)
                    };
                    Process.Start(start);
                    return 0;
                }
            }
            return 1;
        }

但上面的代码注册到IE中后,确实可以接管IE的下载,但有时候用户可能想不让这个下载器下载,比如按住Ctrl键就用默认的IE或其它下载工具下载,我如何放过下载,而不接管呢?我试了即使我把这个方法内的代码全部注释掉,它也已经屏蔽了其它所有下载,返回值好像怎么改也没用,不知道如何实现?

问题补充:

请不要告诉我用BHO拦截WebBrowser的BeforeNavigate事件来拦截下载,如果服务端试动态生成的下载链接,这种方式无法拿到文件名和文件类型,或者要自己多加请求以牺牲性能为代价的方法暂时不考虑。

空明流光的主页 空明流光 | 初学一级 | 园豆:106
提问于:2013-11-19 19:46
< >
分享
所有回答(1)
0

为什么我不进Download方法,

Csharp.牛牛 | 园豆:206 (菜鸟二级) | 2015-10-29 23:00

这个网上有一个完整的项目源码,你在google或bing上用英文搜一搜,我已经找不到当年的代码了。

支持(0) 反对(0) 空明流光 | 园豆:106 (初学一级) | 2015-11-11 16:09
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册