views:

42

answers:

3

Can anyone tell me how to get the Environment.SpecialFolders.MyVideo folder in .NET 2.0?

In .NET 4.0, the MyVideo folder is listed in the enum Environment.SpecialFolders, but under .NET 2.0 it is not existant. Which way would you go if you had to find that folder under .NET 2.0 with different Windows localisations and OS versions?

A: 

Probably you can use os environment variables in your file or folder path like %WINDIR%

You can find more here http://technet.microsoft.com/en-us/library/cc749104%28WS.10%29.aspx

Jahangir Zinedine
+2  A: 

You'll have to pinvoke SHGetFolderPath yourself. Get the declaration and sample usage from pinvoke.net. Pass 14 for the 2nd argument. Requires at least Windows XP.

Hans Passant
This is what I used now (and works, Thanks) : public class Folders{ public static string getFolderPath(CSIDL folder){ StringBuilder SB = new StringBuilder(); SHGetFolderPath(IntPtr.Zero, (int) folder, IntPtr.Zero, 0x0000, SB); return SB.ToString(); } [DllImport("shell32.dll")] private static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder, IntPtr hToken, uint dwFlags, [Out] StringBuilder pszPath); public enum CSIDL { MYVIDEO = 14 } }
Akku
There's a nasty bug in that code, make it new StringBuilder(259).
Hans Passant
string UserVideoPath = Folders.getFolderPath(Folders.CSIDL.MYVIDEO); More folder pointers are: ADMINTOOLS = 0x30, ALTSTARTUP = 0x1d, APPDATA = 0x1a, BITBUCKET = 10, CDBURN_AREA = 0x3b, COMMON_ADMINTOOLS = 0x2f, COMMON_ALTSTARTUP = 30, COMMON_APPDATA = 0x23, COMMON_DESKTOPDIRECTORY = 0x19, COMMON_DOCUMENTS = 0x2e, COMMON_FAVORITES = 0x1f, COMMON_MUSIC = 0x35, COMMON_PICTURES = 0x36, COMMON_PROGRAMS = 0x17,
Akku
COMMON_STARTMENU = 0x16,COMMON_STARTUP = 0x18,COMMON_TEMPLATES = 0x2d,COMMON_VIDEO = 0x37,CONTROLS = 3,COOKIES = 0x21,DESKTOP = 0,DESKTOPDIRECTORY = 0x10,DRIVES = 0x11,FAVORITES = 6,FLAG_CREATE = 0x8000,FONTS = 20,HISTORY = 0x22,INTERNET = 1,INTERNET_CACHE = 0x20,LOCAL_APPDATA = 0x1c,MYDOCUMENTS = 12,MYMUSIC = 13,MYPICTURES = 0x27,MYVIDEO = 14,NETHOOD = 0x13,NETWORK = 0x12,PERSONAL = 5,PRINTERS = 4,PRINTHOOD = 0x1b,PROFILE = 40,PROFILES = 0x3e,PROGRAM_FILES = 0x26,PROGRAM_FILES_COMMON = 0x2b,PROGRAMS = 2,RECENT = 8,SENDTO = 9,STARTMENU = 11,STARTUP = 7,
Akku
SYSTEM = 0x25,TEMPLATES = 0x15,WINDOWS = 0x24 Yeah, thanks, it should be a limited new StringBuilder (259); Added these pointers for reference, I'm sure I'll see this question again sometime.
Akku
+1  A: 

To get this directory try this:

DirectoryInfo di = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
string path = di.FullName.Replace(di.Name, "Videos");
Andriy Shvay
`di.FullName.Replace(di.Name, "Videos");` what's for??
abatishchev
In di you have info about Documents folder, then in the path i change Documents folder name on Videos - and here you go
Andriy Shvay
Seems kinda hacky, even if its short. I accepted another answer, but if this works it looks neat :-)
Akku
Well my asumption is that Documents, Picures, Music, Video folders have the same parent folder, so you just have to change name to get the right one) System.Diagnostics.Process.Start(path); - works fine
Andriy Shvay