可以在.NET的OpenFileDialog进行设置,让用户选择一个.lnk文件 [英] Can the .NET OpenFileDialog be setup to allow the user to select a .lnk file

查看:222
本文介绍了可以在.NET的OpenFileDialog进行设置,让用户选择一个.lnk文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示一个对话框,允许用户选择一个快捷方式(.lnk)文件。我的问题是,对话试图获取文件/ URL快捷方式指向而不是.lnk文件本身。

I want to show a dialog that will allow the user to select a shortcut (.lnk) file. My problem is that the dialog tries to get the file/URL the shortcut is pointing to rather then the .lnk file itself.

如何使它允许的.lnk被选中的文件吗?

How can I make it allow .lnk files to be selected?

推荐答案

您可以使用 OpenFileDialog.DereferenceLinks 属性,以影响该行为(<一href="http://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.dereferencelinks.aspx">see DOC )。

You can use the OpenFileDialog.DereferenceLinks property to influence that behaviour (see doc).

var dlg = new OpenFileDialog();
dlg.FileName = null;
dlg.DereferenceLinks = false;

if (dlg.ShowDialog() == DialogResult.OK) {
    this.label1.Text = dlg.FileName;
}

var dlg = new OpenFileDialog();
dlg.FileName = null; 
this.openFileDialog1.Filter = "Link (*.lnk)|*.lnk";

if (dlg.ShowDialog() == DialogResult.OK) {
    this.label1.Text = dlg.FileName;

这两种方法产生的.lnk 文件,但第一种方法允许的.lnk 文件选择<强>或普通文件,而第二个选择的.lnk 文件。

Both methods yield a .lnk file, however the first approach allows the selection of .lnk files or normal files, while the second only selects .lnk files.

这篇关于可以在.NET的OpenFileDialog进行设置,让用户选择一个.lnk文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆