Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Accessing the shell

Accessing the shell

Scheduled Pinned Locked Moved C#
csharplinuxquestion
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Is there any way to access the shell in C# ? I want to list the contents of the desktop.... Thanks!:confused:

    J 1 Reply Last reply
    0
    • L Lost User

      Is there any way to access the shell in C# ? I want to list the contents of the desktop.... Thanks!:confused:

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      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

      L 1 Reply Last reply
      0
      • J James T Johnson

        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

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        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,...

        J 1 Reply Last reply
        0
        • L Lost User

          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,...

          J Offline
          J Offline
          James T Johnson
          wrote on last edited by
          #4

          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

          L 1 Reply Last reply
          0
          • J James T Johnson

            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

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            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...?

            J 1 Reply Last reply
            0
            • L Lost User

              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...?

              J Offline
              J Offline
              James T Johnson
              wrote on last edited by
              #6

              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

              L 1 Reply Last reply
              0
              • J James T Johnson

                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

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Okay, now I understand. Depending on the operating system, you still have to write different code. Thank you very much for your remarks! Kind Regards, Ludwig

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups