views:

354

answers:

4

I'm programatically creating a folder using C# and need to set the default view of the folder to "Thumbnails".

+2  A: 

The relevant registry keys are listed here: http://support.microsoft.com/kb/812003

However, "Remember each folder's view settings" would need to be selected in order for changes in that KB article to take effect. It seems like it would be 'bad behavior' for a program to change this without specific user prompting.

Update: For the desktop.ini, I've never had much luck using it; however, this site seems to list a few CLSIDs that may be worth looking into: http://www.xs4all.nl/~hwiegman/desktopini.html

Specifically the [ExtShellFolderViews] section. I gave it a whirl but didn't have any luck.

opello
I think the behavior is okay since the application is creating the folder -- kind of like how javascript can close a window that it already opened.
Matt Brunell
I was looking for some registry key to change, but I didn't/don't see how to connect the registry to the folder. You are correct in that I don't want to override the "Remember each folder's view settings" for the user. Is it possible to use a desktop.ini file?
pdavis
I added what I found about desktop.ini, but I didn't have any luck with that route. The other caveat is that the registry setting for WinXP/2k is limited to 400 folders. Vista/2k8/Win7 seems configurable, but you could still end up losing your preferred style if enough folders were opened and view settings stored it seems.
opello
A: 

Assuming you do this yourself using a ListView, you can either set the View property to LargeIcon or if that's not enough (you mention Thumbnails) you should probably set OwnerDraw to true for the items and draw them yourself.

Abel
I doubt "LargeIcon" is the same as "Thumbnail".
Dave Swersky
A: 

The only way I know to manipulate this setting is through pInvoke, but it looks like there is no message to set the view to Thumbnails. Here is a code snippet targeted to WinXP.

Dave Swersky
A: 

Call IFolderView::SetCurrentViewMode with FVM_THUMBSTRIP

Not sure which explorer window you should query IFolderView from though. There could be multiple explorer windows on the user's desktop, those running under a higher integrity level would deny you access if you are from a lower integrity level.

Sheng Jiang 蒋晟
After creating the folder I am opening it up in an explorer window so this might be the way to go if it is a permanent change. Meaning, after the user closes the folder and comes back to it, it is still in the Thumbnail view (assuming they have "Remember each folder's view settings" set to true). I found an example in VB (http://www.vbforums.com/showthread.php?t=409476) but will need to convert it to C#.
pdavis
ShellExecute does not give you control after the process is launched. You could write a BHO to check if the parent process is your application and the current exe is explorer.exe. If both are true, you can obtain commands from your application via interprocess communication methods to execute, like changing the view mode in the DocumentComplete event handler. http://blog.joycode.com/jiangsheng/archive/2004/09/17/33756.aspx is the method to get IFolderView from IShellBrowser.
Sheng Jiang 蒋晟
In a BHO you would get the IShellBrowser interface from IServiceProvider (http://www.codeproject.com/KB/shell/AutomateShellWindow.aspx).
Sheng Jiang 蒋晟