Accessing the shell
-
Is there any way to access the shell in C# ? I want to list the contents of the desktop.... Thanks!:confused:
Well this isn't done via the shell but you can get this list by doing this.
public string [] GetFilesOnDesktop() {
string desktop = System.Environment.GetFolderPath( System.Environment.SpecialFolder.DesktopDirectory );
return System.IO.Directory.GetFiles(desktop);
}I'm not familiar with the Shell API but you should be able to also use PInvoke to call the functions you would normally. HTH, James Sonork ID: 100.11138 - Hasaki "Smile your little smile, take some tea with me awhile. And every day we'll turn another page. Behind our glass we'll sit and look at our ever-open book, One brown mouse sitting in a cage." "One Brown Mouse" from Heavy Horses, Jethro Tull 1978
-
Well this isn't done via the shell but you can get this list by doing this.
public string [] GetFilesOnDesktop() {
string desktop = System.Environment.GetFolderPath( System.Environment.SpecialFolder.DesktopDirectory );
return System.IO.Directory.GetFiles(desktop);
}I'm not familiar with the Shell API but you should be able to also use PInvoke to call the functions you would normally. HTH, James Sonork ID: 100.11138 - Hasaki "Smile your little smile, take some tea with me awhile. And every day we'll turn another page. Behind our glass we'll sit and look at our ever-open book, One brown mouse sitting in a cage." "One Brown Mouse" from Heavy Horses, Jethro Tull 1978
Thanks for the answer! I did try that, but the idea is to create a little explorer-like application in C#, with a tree listing of all contents of the desktop (the virtual directory, not the physical!). So the question was in fact: how do I access virtual folders like desktop, my computer, my documents,...
-
Thanks for the answer! I did try that, but the idea is to create a little explorer-like application in C#, with a tree listing of all contents of the desktop (the virtual directory, not the physical!). So the question was in fact: how do I access virtual folders like desktop, my computer, my documents,...
Anonymous wrote: So the question was in fact: how do I access virtual folders like desktop, my computer, my documents,... OK, I believe the shell functions are nothing more than a COM object, so you can use the COM object via PInvoke. Unfortunately I can't give you any more than that, PInvoke and Shell programming are both something I haven't delved into much (PInvoke) or at all (Shell programming). I can however point you to a place that might have already answered or question, or if it hasn't been answered you can ask it there. The DOTNET mailing list is probably the best mailing list out there dealing with .NET. Hope I pointed you in the right direction, James Sonork ID: 100.11138 - Hasaki "Smile your little smile, take some tea with me awhile. And every day we'll turn another page. Behind our glass we'll sit and look at our ever-open book, One brown mouse sitting in a cage." "One Brown Mouse" from Heavy Horses, Jethro Tull 1978
-
Anonymous wrote: So the question was in fact: how do I access virtual folders like desktop, my computer, my documents,... OK, I believe the shell functions are nothing more than a COM object, so you can use the COM object via PInvoke. Unfortunately I can't give you any more than that, PInvoke and Shell programming are both something I haven't delved into much (PInvoke) or at all (Shell programming). I can however point you to a place that might have already answered or question, or if it hasn't been answered you can ask it there. The DOTNET mailing list is probably the best mailing list out there dealing with .NET. Hope I pointed you in the right direction, James Sonork ID: 100.11138 - Hasaki "Smile your little smile, take some tea with me awhile. And every day we'll turn another page. Behind our glass we'll sit and look at our ever-open book, One brown mouse sitting in a cage." "One Brown Mouse" from Heavy Horses, Jethro Tull 1978
-
Thanks, great link! However, something else.. using COM-objects, is that good programming practice...? I mean, this way you put some Windows-only code into the application, or am I wrong...?
Anonymous wrote: I mean, this way you put some Windows-only code into the application, or am I wrong...? Correct, but you'll have to use different methods for getting a list of files on the desktop for each operating system anyway. If you place all your OS specific stuff in a separate assembly then you can load the proper assembly at runtime. FWIW I'm not sure how much of Windows.Forms is going to be ported; it isn't a part of the CLI specs but I believe the Mono project is going to port some of it over anyway. James Sonork ID: 100.11138 - Hasaki "Smile your little smile, take some tea with me awhile. And every day we'll turn another page. Behind our glass we'll sit and look at our ever-open book, One brown mouse sitting in a cage." "One Brown Mouse" from Heavy Horses, Jethro Tull 1978
-
Anonymous wrote: I mean, this way you put some Windows-only code into the application, or am I wrong...? Correct, but you'll have to use different methods for getting a list of files on the desktop for each operating system anyway. If you place all your OS specific stuff in a separate assembly then you can load the proper assembly at runtime. FWIW I'm not sure how much of Windows.Forms is going to be ported; it isn't a part of the CLI specs but I believe the Mono project is going to port some of it over anyway. James Sonork ID: 100.11138 - Hasaki "Smile your little smile, take some tea with me awhile. And every day we'll turn another page. Behind our glass we'll sit and look at our ever-open book, One brown mouse sitting in a cage." "One Brown Mouse" from Heavy Horses, Jethro Tull 1978