1

我开发了一个程序,它有一个网络浏览器。

我想设置打开的文件对话框的默认路径(初始目录)。[如何访问由 WebBrowser 控件打开的文件浏览器]

以及如何由我自动设置文件?

4

2 回答 2

1

您可以使用 Windows API (user32.dll) 更改目录对话框。例如:获取 FileDialog 窗口的处理程序

[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

private const int WM_SETTEXT = 0x000C;

IntPtr FileDialogHandle = FindWindow("#32770", "Choose File To Upload");

获取 FileDialog 窗口的处理程序文本框文件地址和发送路径:

IntPtr iptrHWndControl = GetDlgItem(FileDialogHandle , 1148);
HandleRef hrefHWndTarget = new HandleRef(null, iptrHWndControl);
SendMessage(hrefHWndTarget, WM_SETTEXT, IntPtr.Zero, "your file path");
于 2013-04-09T12:11:50.033 回答
0

无法设置默认路径。

于 2012-06-28T11:16:48.200 回答