开发者

How do I use the OpenFileDialog class such that it opens on the Network area as default?

How do I use the OpenFileDialog class (in C#, WPF etc.) such that it opens on the Network area as default?

This does not work:

  OpenFileDialog openFileDialog1 = new OpenFileDialog();
  openFileDialog1.InitialDirectory = "Network";

I also tried having "\" as an InitialDirectory and that did not work.

I also tried having "\\" as an InitialDirectory and that 开发者_开发问答did not work either.


I haven't tried it, but this should work:

openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.NetworkShortcuts);

Environment.GetFolderPath returns the path corresponding to an Environment.SpecialFolder enumeration entry as a string.

Environment.SpecialFolder.NetworkShortcuts is defined as

A file system directory that contains the link objects that may exist in the My Network Places virtual folder.


Customize Your Open File Dialog from the Microsoft MSDN Magazine has a lot of information on the dialog. I haven't had chance to read it all, but this caught my eye:

A Custom Places Bar
...

You'll need a REG_SZ entry if the name of the folder is an absolute or relative path. You need to use the folder-specific number if you want to target a special folder (see Figure 6 for a list). In this case, a REG_DWORD entry is needed.

Figure 6

Folder IDs

ID Folder
0 Desktop
2 Programs folder on Start menu
3 Control Panel
4 Printers
5 My Documents
6 Favorites
7 Startup folder on Start menu
8 Recent Files
9 Send To
10 Recycle Bin
12 Start menu
17 My Computer
18 My Network Places
20 Fonts

I've missed a whole load of stuff out (because it's a very long article), but it looks like you can set the ID value to 18 to get your network places. However, as @Nelson points out this might part looks like it's adding an entry to the bar, so double check it before using. As I said before the post I've linked to contains a lot of information, so what you need may well be buried somewhere in it.

Update:

On Windows 7 PC's it doesn't work. eg:

OpenDialogPlaces o = new OpenDialogPlaces();
//o.Places.Add(18);
//o.Places.Add(5);
//o.Places.Add(6);
o.Init();
o.OpenDialog.ShowDialog();
o.Reset();

Still shows everything in the left-hand:

How do I use the OpenFileDialog class such that it opens on the Network area as default?

It did work in previous versions of Windows:

How do I use the OpenFileDialog class such that it opens on the Network area as default?

Another thing it appears Microsoft has changed the ComDlg32's location, I tried both places but no luck.

How do I use the OpenFileDialog class such that it opens on the Network area as default?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜