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. Get folders like the one for mega, drop box

Get folders like the one for mega, drop box

Scheduled Pinned Locked Moved C#
csharpasp-netdotnetwindows-adminquestion
5 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.
  • D Offline
    D Offline
    Duc Axenn
    wrote on last edited by
    #1

    Hi, i would to make an explorer to add some methods i need behind. I tried a lot of things but many are deprecated. I'm under windows 10 x64. I want to make my app under .net core. I tried SHGetSpecialFolderLocation but the name i retrieve is in chinese... i don't understand why. I saw with windows 10 it's better to use knownfolderid but i search in my registrykeys and i didn't find mega key, but it uses a clsid. Should it a good idea to ask to the registry or is there another method ? i want to make something classic, with "mycomputer" root, make drives under it (it's ok for this part), have clouds folder also... And i will try to get default icons, i have some methods using win32.dll (if you have better i will happy to have more informations).

    D 1 Reply Last reply
    0
    • D Duc Axenn

      Hi, i would to make an explorer to add some methods i need behind. I tried a lot of things but many are deprecated. I'm under windows 10 x64. I want to make my app under .net core. I tried SHGetSpecialFolderLocation but the name i retrieve is in chinese... i don't understand why. I saw with windows 10 it's better to use knownfolderid but i search in my registrykeys and i didn't find mega key, but it uses a clsid. Should it a good idea to ask to the registry or is there another method ? i want to make something classic, with "mycomputer" root, make drives under it (it's ok for this part), have clouds folder also... And i will try to get default icons, i have some methods using win32.dll (if you have better i will happy to have more informations).

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You haven't explained any kind of problem you're having. I'm going to guess that you're trying to use SHGetSpecialFolder location to get the paths to cloud folder. That will not work as they are not part of the Windows file system. AFAIK, there is no standard method to get cloud folder paths. You'd have to write support modules for each cloud provider you want to support and ask the user for their username and password to get into those folders.

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
      Dave Kreskowiak

      D 1 Reply Last reply
      0
      • D Dave Kreskowiak

        You haven't explained any kind of problem you're having. I'm going to guess that you're trying to use SHGetSpecialFolder location to get the paths to cloud folder. That will not work as they are not part of the Windows file system. AFAIK, there is no standard method to get cloud folder paths. You'd have to write support modules for each cloud provider you want to support and ask the user for their username and password to get into those folders.

        Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
        Dave Kreskowiak

        D Offline
        D Offline
        Duc Axenn
        wrote on last edited by
        #3

        hi, thanks for your answer. I tried several things, even before i tried to read sources from this example I used

        IntPtr m_pIDL = IntPtr.Zero;
        hRes = ShellAPI.SHGetSpecialFolderLocation(IntPtr.Zero, CSIDL.CSIDL_DESKTOP, ref m_pIDL);

        but it's deprecated, so i used

                hRes = ShellAPI.SHGetFolderLocation(IntPtr.Zero, 0, IntPtr.Zero,0, out m\_pIDL);
        

        For retrieve informations i used

                SHFILEINFO shInfo = new SHFILEINFO();
                ShellAPI.SHGetFileInfo(m\_pIDL, 0, out shInfo, (uint)Marshal.SizeOf(shInfo),
                    SHGFI.DisplayName | //0x000000200
                    SHGFI.PIDL | //0x000000008
                    SHGFI.SmallIcon |//0x000000001
                    SHGFI.SystemIconIndex //0x000004000
                );
        

        But i get

        畂敲畡

        as display name, and 34 as iIcon in all cases. Which means "toc toc" (knocking) according to google translate. I can't go more forward, i'm totally blind because of that. This example is interesting because it give me what i need, i have one drive & mega folders and it seems there is no special instruction to have it, it lists elements by using

        EnumObjects

        This is why i would to use some elements under .net core and learn how to use windows api, instead of using c# with methods from Directory. If i understand well it's a handle (pointeur?). SHFILEINFO

        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public struct SHFILEINFO
        {
        public IntPtr hIcon;

            public int iIcon;
        
            public uint dwAttributes;
        
            \[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)\]
            public string szDisplayName;
        
            \[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)\]
            public string szTypeName;
        }
        
            \[DllImport("shell32.dll")\]
            //public static extern Int32 SHGetFolderLocation(IntPtr hwnd, int csidl, HANDLE hToken, DWORD dwFlags, PIDLIST\_ABSOLUTE\* ppidl);
            public static extern int SHGetFolderLocation(IntPtr hwndOwner, int csidl, IntPtr hToken, uint dwReserved, out IntPtr ppidl);
        
        
            \[DllImport("shell32.dll", CharSet = CharSet.Auto)\]
            public static extern IntPtr SHGetFileInfo(string path, uint attributes, out SHFILEINFO fileInfo, uint size, uint flags);
        
            \[DllImport("shell32.dll")\]
            public static extern IntPtr SHG
        
        D 1 Reply Last reply
        0
        • D Duc Axenn

          hi, thanks for your answer. I tried several things, even before i tried to read sources from this example I used

          IntPtr m_pIDL = IntPtr.Zero;
          hRes = ShellAPI.SHGetSpecialFolderLocation(IntPtr.Zero, CSIDL.CSIDL_DESKTOP, ref m_pIDL);

          but it's deprecated, so i used

                  hRes = ShellAPI.SHGetFolderLocation(IntPtr.Zero, 0, IntPtr.Zero,0, out m\_pIDL);
          

          For retrieve informations i used

                  SHFILEINFO shInfo = new SHFILEINFO();
                  ShellAPI.SHGetFileInfo(m\_pIDL, 0, out shInfo, (uint)Marshal.SizeOf(shInfo),
                      SHGFI.DisplayName | //0x000000200
                      SHGFI.PIDL | //0x000000008
                      SHGFI.SmallIcon |//0x000000001
                      SHGFI.SystemIconIndex //0x000004000
                  );
          

          But i get

          畂敲畡

          as display name, and 34 as iIcon in all cases. Which means "toc toc" (knocking) according to google translate. I can't go more forward, i'm totally blind because of that. This example is interesting because it give me what i need, i have one drive & mega folders and it seems there is no special instruction to have it, it lists elements by using

          EnumObjects

          This is why i would to use some elements under .net core and learn how to use windows api, instead of using c# with methods from Directory. If i understand well it's a handle (pointeur?). SHFILEINFO

          [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
          public struct SHFILEINFO
          {
          public IntPtr hIcon;

              public int iIcon;
          
              public uint dwAttributes;
          
              \[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)\]
              public string szDisplayName;
          
              \[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)\]
              public string szTypeName;
          }
          
              \[DllImport("shell32.dll")\]
              //public static extern Int32 SHGetFolderLocation(IntPtr hwnd, int csidl, HANDLE hToken, DWORD dwFlags, PIDLIST\_ABSOLUTE\* ppidl);
              public static extern int SHGetFolderLocation(IntPtr hwndOwner, int csidl, IntPtr hToken, uint dwReserved, out IntPtr ppidl);
          
          
              \[DllImport("shell32.dll", CharSet = CharSet.Auto)\]
              public static extern IntPtr SHGetFileInfo(string path, uint attributes, out SHFILEINFO fileInfo, uint size, uint flags);
          
              \[DllImport("shell32.dll")\]
              public static extern IntPtr SHG
          
          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          What's the return value from your SHGetFileInfo call. If it's 0, then some error occurred and you're going to have to use GetLastError to get the error code to see what happened.

          Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
          Dave Kreskowiak

          D 1 Reply Last reply
          0
          • D Dave Kreskowiak

            What's the return value from your SHGetFileInfo call. If it's 0, then some error occurred and you're going to have to use GetLastError to get the error code to see what happened.

            Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
            Dave Kreskowiak

            D Offline
            D Offline
            Duc Axenn
            wrote on last edited by
            #5

            Hi, i have an hexadecimal value for the return value. I ask myself if i must continue to this way, i read somewhere else it was an old way to do it like a c++ copy/paste. I would to have something quick, with all default icons (i don't know another way for folders than to use win32.dll this is why i thought about make all with api methods) Meanwhile, to go forward i found a way to get mega folders, i post here if it can help others.

                    var identity = System.Security.Principal.WindowsIdentity.GetCurrent();
                    string userName = identity.Name.ToString();
                    string userSID = identity.User.ToString();
                    List MegaFolderPaths = new List();
            
                    RegistryKey clsidKey = Registry.Users.OpenSubKey($"{userSID}\\\\Software\\\\Classes\\\\CLSID");
            
                    //Get all the sub keys it contains
                    foreach (string subKey in clsidKey.GetSubKeyNames())
                    {
                        RegistryKey clsidSubKey = Registry.Users.OpenSubKey($"{userSID}\\\\Software\\\\Classes\\\\CLSID\\\\{subKey}\\\\Instance\\\\InitPropertyBag");
            
                        if (clsidSubKey == null)
                            continue;
            
                        string defaultValue = (string)clsidSubKey.GetValue("TargetFolderPath");
            
                        if (!string.IsNullOrEmpty(defaultValue))
                            MegaFolderPaths.Add(defaultValue);
                    }
            

            ------------------- Edit: for the chinese character i didn't see i forgot to add this

            [DllImport("shell32.dll", CharSet = CharSet.Auto)]

            above

                public static extern Int32 SHGetFileInfo(IntPtr pIDL, uint dwFileAttributes,
                                        out SHFILEINFO psfi, uint cbFileInfo, uint uFlags);
            
            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