我正在使用WatIn登录webSite并下载文件。当我看到下载对话框时,我没有太多电源下载对话框播放我只需按下保存按钮和文件下载到默认文件夹的默认文件,这正是我的意思需要这个文件夹的路径。我基本上知道C:\Users\UserNAme\Favorites\Downloads
,但我需要100%肯定,因为用户可以改变这条路径。
如何查找上次下载的文件路径或broser的默认下载文件夹。
这里是我需要下载的代码
Thread.Sleep(10000);
IntPtr prevChild = FindWindow("IEFrame", "Reports | ACCESS - Internet Explorer");
Thread.Sleep(3000);
IntPtr currChild = FindWindowEx(prevChild, 0, "Frame Notification Bar", "");
Thread.Sleep(3000);
IntPtr currChild2 = FindWindowEx(currChild, 0, "DirectUIHWND", "");
Thread.Sleep(3000);
PostMessage(currChild2, WM_KEYDOWN, VK_F6, 2);
Thread.Sleep(3000);
PostMessage(currChild2, WM_KEYDOWN, VK_TAB, 2);
Thread.Sleep(3000);
PostMessage(currChild2, WM_KEYDOWN, VK_ENTER, 2);
答案 0 :(得分:2)
IE 11:默认它将转到%homedrive %% homepath%\ downloads或%userprofile%\ downloads - 结果是相同的。如果它不是默认值,则会在键'HKEY_CURRENT_USER \ Software \ Microsoft \ Internet Explorer \ Main'中有一个名为'Default Download Directory'的REG_SZ值
编辑:
String path = String.Empty;
RegistryKey rKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main");
if (rKey != null)
path = (String)rKey.GetValue("Default Download Directory");
if (String.IsNullOrEmpty(path))
path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\downloads";