Beispiel #1
0
        public override void NewFolder()
        {
            FolderAttributes newFolderAttrs = FolderAttributes.Folder | FolderAttributes.HasPropSheet |
                                              FolderAttributes.CanMove | FolderAttributes.CanDelete |
                                              FolderAttributes.CanRename | FolderAttributes.CanCopy |
                                              FolderAttributes.CanLink | FolderAttributes.Browsable |
                                              FolderAttributes.DropTarget;

            string spath = CreateNewFolder("", "New Folder");

            if (string.IsNullOrEmpty(spath))
            {
                return;
            }
            //refrash all views
            IntPtr pParrent = ItemIdList.Create(null, PathData).Ptr;

            Shell32.SHChangeNotify(ShellChangeEvents.UpdateDir,
                                   ShellChangeFlags.IdList | ShellChangeFlags.Flush,
                                   pParrent,
                                   IntPtr.Zero);
            Marshal.FreeCoTaskMem(pParrent);

            using (MemoryStream ms = new MemoryStream())
            {
                BinaryWriter w = new BinaryWriter(ms, Encoding.Default);
                w.Write(0);
                w.Write(spath);
                w.Write((int)newFolderAttrs);
                IFileObject foNew = new FileObject();
                foNew.Name     = spath;
                foNew.IsFolder = true;
                byte[] btFo = FileObject.ToByteArray(foNew);
                w.Write((int)btFo.Length);
                w.Write(btFo, 0, btFo.Length);
                byte[] persist = ms.ToArray();

                var lst = PathData.ToList();
                lst.Add(persist);

                IntPtr pNew = ItemIdList.Create(null, lst.ToArray()).Ptr;
                Shell32.SHChangeNotify(
                    ShellChangeEvents.MkDir,
                    ShellChangeFlags.IdList | ShellChangeFlags.Flush,
                    pNew,
                    IntPtr.Zero);
                Marshal.FreeCoTaskMem(pNew);
            }

            using (MemoryStream ms = new MemoryStream())
            {
                BinaryWriter w = new BinaryWriter(ms, Encoding.Default);
                w.Write(0);
                w.Write(spath);
                w.Write((int)newFolderAttrs);
                byte[] persist = ms.ToArray();

                IntPtr pNewFolder = ItemIdList.Create(null, new byte[][] { persist }).Ptr;
                if (ShellView != null)
                {
                    ShellView.SelectItem(pNewFolder, _SVSIF.SVSI_EDIT | _SVSIF.SVSI_FOCUSED | _SVSIF.SVSI_ENSUREVISIBLE);
                }
                Marshal.FreeCoTaskMem(pNewFolder);
            }
        }