开发者

Is there a way to customize the OpenFileDialog to select folders instead of a file?

开发者 https://www.devze.com 2023-02-06 14:02 出处:网络
I have a VB/C# .NET 2.0 project that, if possible, I would like to customize the OpenFileDialog box to select a directory rather than a file. The rea开发者_开发问答son for this is because the FolderBr

I have a VB/C# .NET 2.0 project that, if possible, I would like to customize the OpenFileDialog box to select a directory rather than a file. The rea开发者_开发问答son for this is because the FolderBrowserDialog is ugly and a pain for most of my users to navigate using.

I know how to filter extensions using OpenFileDialog, but is there a flag or variable I can set that will allow me to only show directories and select those directories that is built into .NET? And if not, what is a good third party dialog to use/where should I begin if I am to create my own?

I apologize, I do not have much experience creating frontends. Any help or direction on this would be greatly appreciated :)


After checking the question that Mayank posted, I found out that there is no native way to do this in .NET. However, one of the posts by Scott Wisniewski yielded the exactly what I was looking for.

The only thing I had to do to make this work in .NET 2.0 was add the following code to my project in a file called ExtensionAttribute.cs. This method is not needed in .NET 3.5+, but please note that this is reported to not work at all with Visual Studio 2005.

namespace System.Runtime.CompilerServices
{
   [AttributeUsage(AttributeTargets.Method)]
   public sealed class ExtensionAttribute : Attribute
   {
      public ExtensionAttribute() { }
   }
}

Again, this code snippet only works with Visual Studio 2008, it will not work with VS 2005.

0

精彩评论

暂无评论...
验证码 换一张
取 消