コード例 #1
0
        /// <summary>
        /// Ask the user where logs should be saved
        /// </summary>
        /// <param name="path">folder to save logs to</param>
        /// <returns>ok/cancel</returns>
        DialogResult IUserInterface.PromptForLoggingFolder(out string path)
        {
            //string initialPath = Environment.CurrentDirectory;

            Shell32.ShellClass shell  = new Shell32.ShellClass();
            Shell32.Folder2    folder = (Shell32.Folder2)shell.BrowseForFolder(
                this.Handle.ToInt32(),
                "Select Folder...",
                0, // Options
                this.lumberjack.Settings.LogFolderPath
                );
            path = folder.Self.Path;
            this.folderLabel.Text = path;

            /*
             * OpenFileDialog dialog = new OpenFileDialog();
             * dialog.CheckPathExists = true;
             * dialog.InitialDirectory = Settings.Default.LogFolderPath;
             * dialog.ValidateNames = true;
             * DialogResult result = dialog.ShowDialog(this);
             * if (result == DialogResult.OK)
             * {
             *  string path = dialog.FileName;
             *  path = Path.GetDirectoryName(path);
             *  Settings.Default.LogFolderPath = path;
             * }
             */
            //Environment.CurrentDirectory = initialPath;
            return(DialogResult.OK); // TODO: really?
        }
        public override void RequestRoot(TreeViewFolderBrowserHelper helper)
        {
            _helper = helper;
            AttachSystemImageList(helper);
            //
            // setup up root node collection
            switch (helper.TreeView.RootFolder)
            {
            case Environment.SpecialFolder.Desktop:
                Shell32.Folder2 desktopFolder = (Shell32.Folder2)_shell.GetDesktop();
                // create root node <Desktop>
                TreeNodePath desktopNode = CreateTreeNode(helper, desktopFolder.Title, desktopFolder.Self.Path, false, false, true);
                helper.TreeView.Nodes.Add(desktopNode);
                desktopNode.Tag = desktopFolder;
                //
                Shell32.Folder2 myComputer = (Shell32.Folder2)_shell.Shell.NameSpace(Shell32.ShellSpecialFolderConstants.ssfDRIVES);
                foreach (Shell32.FolderItem fi in desktopFolder.Items())
                {
                    if (!fi.IsFolder)
                    {
                        continue;
                    }
                    //
                    TreeNodePath node = CreateTreeNode(helper, fi.Name, fi.Path, true, false, true);
                    node.Tag = fi;
                    desktopNode.Nodes.Add(node);
                    //
                    if (_shell.Shell.NameSpace(Shell32.ShellSpecialFolderConstants.ssfDRIVES).Title == fi.Name)
                    {
                        _rootCollection = node.Nodes;
                    }
                }
                break;

            case Environment.SpecialFolder.MyComputer:
                this.FillMyComputer(((Shell32.Folder2)_shell.Shell.NameSpace(Shell32.ShellSpecialFolderConstants.ssfDRIVES)).Self, helper.TreeView.Nodes, helper);
                break;

            default:
                // create root node with specified SpecialFolder
                Shell32.Folder2 root     = (Shell32.Folder3)_shell.Shell.NameSpace(helper.TreeView.RootFolder);
                TreeNodePath    rootNode = CreateTreeNode(helper, root.Title, root.Self.Path, true, false, true);
                rootNode.Tag = root.Self;
                helper.TreeView.Nodes.Add(rootNode);
                _rootCollection = rootNode.Nodes;
                break;
            }
        }
コード例 #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            Shell32.ShellClass shell  = new Shell32.ShellClass();
            Shell32.Folder2    folder = (Shell32.Folder2)shell.BrowseForFolder(
                this.Handle.ToInt32(),                         // Window handle as type int
                "Select Folder...",                            // Window caption
                0,                                             // Option flags...the only part you'll have to hard-code values for if you want them
                Shell32.ShellSpecialFolderConstants.ssfDESKTOP // Optional root folder, default is Desktop
                );
            if (folder == null)
            {
                return;
            }

            this.textBox1.Text = folder.Self.Path;
            outputDir          = folder.Self.Path;;
        }