- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
据我们所知,WPF OpenFileDialog
不再更改应用程序的工作目录,并且 RestoreDirectory
属性“未实现”。但是,在后续打开时,其初始目录默认为上次打开的文件而不是原始工作目录,因此必须将此信息存储在某个地方。我想知道是否可以从用户代码中获取/设置它?
最佳答案
在 Windows 7 上,最近的文件信息存储在注册表的这个键中:
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Comdlg32\OpenSaveMRU
此键下是各种文件扩展名(例如,exe
、docx
、py
等)的子键。
现在,如果您想读取这些值,这将获得存储在子键下的所有路径的列表(改编自 here ):
String mru = @"Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\OpenSavePidlMRU";
RegistryKey rk = Registry.CurrentUser.OpenSubKey(mru);
List<string> filePaths = new List<string>();
foreach (string skName in rk.GetSubKeyNames())
{
RegistryKey sk = rk.OpenSubKey(skName);
object value = sk.GetValue("0");
if (value == null)
throw new NullReferenceException();
byte[] data = (byte[])(value);
IntPtr p = Marshal.AllocHGlobal(data.Length);
Marshal.Copy(data, 0, p, data.Length);
// get number of data;
UInt32 cidl = (UInt32)Marshal.ReadInt16(p);
// get parent folder
UIntPtr parentpidl = (UIntPtr)((UInt32)p);
StringBuilder path = new StringBuilder(256);
SHGetPathFromIDListW(parentpidl, path);
Marshal.Release(p);
filePaths.Add(path.ToString());
}
引用资料:
关于openfiledialog - WPF OpenFileDialog 如何跟踪上次打开文件的目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11144770/
据我们所知,WPF OpenFileDialog 不再更改应用程序的工作目录,并且 RestoreDirectory 属性“未实现”。但是,在后续打开时,其初始目录默认为上次打开的文件而不是原始工作目
据我们所知,WPF OpenFileDialog 不再更改应用程序的工作目录,并且 RestoreDirectory 属性“未实现”。但是,在后续打开时,其初始目录默认为上次打开的文件而不是原始工作目
当我使用这段代码打开一个文件时 if (ofd.ShowDialog() == DialogResult.OK) text = File.ReadAllText(ofd.FileName,
每个文本框旁边有 2 个文本框和 2 个按钮 [...]。是否可以使用一个 OpenFileDialog 并将 FilePath 传递到相应的文本框,基于单击哪个按钮?即...如果我单击第一个按钮并打
我已将 Multiselect 设置为 true 以便能够一次加载多个文件。问题在于它忽略了用户选择文件的顺序,FileNames 列表始终相同(如果我以不同的顺序选择同一组文件)。 我的问题是:是否
我有一个 OpenFileDialog,当用户第一次使用该应用程序时,它应该打开一个特定的路径,比如 %ProgramData%。对于所有连续的术语,它应该打开最后使用的文件夹。 我试过:
我正在尝试完成我的静态 Prompt 类,以便能够从任何地方调用它。但问题是无法使对话框显示。我已经在使用 [STAThread],这是我的代码。 public static string ShowF
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我想知道如何在c#的打开对话框中过滤掉所有不是txt文件的文件。我已经玩这个很久了,但没有任何乐趣。 最佳答案 使用过滤器属性:MSDN Filter 这是关于如何自定义 OpenFile Dialo
我正在使用 C# 开发 winforms 应用程序。我想要实现的是从我使用以下代码的用户那里获取一个文件: OpenFileDialog dlg = new OpenFileDialog(); if
我有这个简单的代码: private void buttonOpen_Click(object sender, EventArgs e) { if (openFileDialog1.ShowD
我的 C# 程序中有以下代码: OpenFileDialog fDialog = new OpenFileDialog(); fDialog.Title = "Open
我在我的 Silverlight 应用程序中使用 OpenFileDialog()。当我使用 ShowDialog() 选择一个文件时,它只是锁定该文件,直到我关闭我的应用程序。 我无法在应用程序运行
我的应用程序的静态 dll 模块中有 WinForms UI 代码。主窗体有一个对话框窗体,当用户需要更改文件路径时调用openfiledialog。如果我在主线程中创建主 winform 对象,那么
如何允许 OpenFileDialog 选择已在另一个应用程序中打开的文件? 目前它不允许我选择一个已经打开的文件。我只需要文件路径,我实际上并没有尝试打开文件(因为它已经打开)但是 OpenFile
我在 WinForms 应用程序中使用 OpenFileDialog,但在调用 OpenFileDialog.ShowDialog( )。 该功能完全按预期运行。问题是在 OpenFileDialog
我想存储在我的字符串数组中选择的文件名。 代码: if (openFileDialog.ShowDialog() == DialogResult.OK) string filename
我想实现一个打开文件对话框或文件浏览器,另外提供一个“预览”按钮来播放当前选择的声音文件(特别是波形格式,此应用程序不需要其他格式)。 我可以使用各种控件(如 TreeView 和列表框)创建自己的表
对于 DLP 软件的一个非常特殊的要求,我正在尝试检测 OpenFileDialogs 并在捕获所选文件后取消文件选择操作。 我该怎么做? 我在鼠标和键盘上放置了一个全局钩子(Hook)。我检测到用户
选择 .dll 文件并按 OK 后,浏览对话框将关闭并重新打开。在它再次打开并按 OK 后,它会毫无问题地取值。 这是我的代码 private void btnBrowse_Click(object
我是一名优秀的程序员,十分优秀!