예제 #1
0
        private void bnAddMonFolder_Click(object sender, System.EventArgs e)
        {
            FolderBrowserDialogEx searchFolderBrowser = new FolderBrowserDialogEx
            {
                SelectedPath  = "",
                Title         = "Add New Monitor Folder...",
                ShowEditbox   = true,
                StartPosition = FormStartPosition.CenterParent
            };

            if (lstFMMonitorFolders.SelectedIndex != -1)
            {
                int n = lstFMMonitorFolders.SelectedIndex;
                searchFolderBrowser.SelectedPath = TVSettings.Instance.LibraryFolders[n];
            }

            if (searchFolderBrowser.ShowDialog(this) == DialogResult.OK)
            {
                if (Directory.Exists(searchFolderBrowser.SelectedPath))
                {
                    TVSettings.Instance.LibraryFolders.Add(searchFolderBrowser.SelectedPath);
                    mDoc.SetDirty();
                    FillFolderStringLists();
                }
            }
        }
예제 #2
0
        private void OpenFileBrowser(object sender, RoutedEventArgs e)
        {
            Button b = sender as Button;

            TextBox tb = null;

            if (b.Name.Contains("Dest"))
            {
                tb = DestBox;
            }
            else if (b.Name.Contains("Source"))
            {
                tb = SourceBox;
            }

            var dlg = new FolderBrowserDialogEx
            {
                ShowNewFolderButton = true,
                ShowEditBox         = true,
                RootFolder          = Environment.SpecialFolder.MyComputer,
                SelectedPath        = tb.Text != String.Empty ? tb.Text : Environment.SpecialFolder.MyComputer.ToString(),
            };

            var result = dlg.ShowDialog();

            tb.Text = result == System.Windows.Forms.DialogResult.OK ? dlg.SelectedPath : tb.Text;
        }
예제 #3
0
        private void SelectFolder_Click(object sender, EventArgs e)
        {
            FolderBrowserDialogEx cfbd = new FolderBrowserDialogEx();

            cfbd.Title               = "Please choose an fMRI run directory";
            cfbd.SelectedPath        = @"C:\";
            cfbd.ShowEditbox         = true;
            cfbd.ShowNewFolderButton = false;
            cfbd.RootFolder          = Environment.SpecialFolder.Desktop;
            cfbd.StartPosition       = FormStartPosition.CenterScreen;

            DialogResult dr           = cfbd.ShowDialog(this);
            string       txtRtnCode   = dr.ToString();
            string       txtRtnFolder = "";

            if (dr == DialogResult.OK)
            {
                txtRtnFolder = cfbd.SelectedPath;
            }

            //for future inits else-where this is how this is done.
            //comboStartPos.DataSource = Enum.GetValues(typeof(FormStartPosition));
            //comboRootFolder.DataSource = Enum.GetValues(typeof(Environment.SpecialFolder));
            //(Environment.SpecialFolder)comboRootFolder.selectedValue
        }
예제 #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            var browser = new FolderBrowserDialogEx();

            browser.SelectedPath        = lastDir;
            browser.ShowNewFolderButton = true;
            browser.ShowEditbox         = true;
            browser.StartPosition       = FormStartPosition.CenterParent;

            if (browser.ShowDialog(this) == DialogResult.OK)
            {
                lastDir = browser.SelectedPath;
                var dir = new DirectoryInfo(lastDir).FullName;

                if (!dir.EndsWith("\\") && !dir.EndsWith("/"))
                {
                    dir += "\\";
                }

                Directories.Add(dir);
            }

            listBox1.SortList();

            button3.Enabled = Directories.Count != 0;
        }
예제 #5
0
            // Factory Methods
            public static FolderBrowserDialogEx PrinterBrowser()
            {
                FolderBrowserDialogEx x = new FolderBrowserDialogEx();

                // avoid MBRO comppiler warning when passing _rootFolderLocation as a ref:
                x.BecomePrinterBrowser();
                return(x);
            }
        private void txtFolderPath_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            FolderBrowserDialogEx dlg = new FolderBrowserDialogEx()
            {
                Title       = "Open Folder",
                ShowEditbox = true
            };

            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                txtFolderPath.Text = dlg.SelectedPath;
            }
        }
예제 #7
0
        private void getDocumentsPath_Click(object sender, RoutedEventArgs e)
        {
            FolderBrowserDialogEx getDocumentsPath = new FolderBrowserDialogEx();

            getDocumentsPath.Description           = "Zu durchsuchenden Root-Ordner wählen";
            getDocumentsPath.ShowNewFolderButton   = false;
            getDocumentsPath.ShowEditBox           = true;
            getDocumentsPath.ShowFullPathInEditBox = true;
            if (getDocumentsPath.ShowDialog() == Forms.DialogResult.OK)
            {
                documentsPath.Text = getDocumentsPath.SelectedPath;
            }
        }
예제 #8
0
        private void Browse()
        {
            using (var browser = new FolderBrowserDialogEx())
            {
                browser.SelectedPath        = tbDirectory.Text;
                browser.ShowNewFolderButton = true;
                browser.Description         = "Select the source directoy";

                if (browser.ShowDialog(this) == DialogResult.OK)
                {
                    tbDirectory.Text = browser.SelectedPath;
                }
            }
        }
예제 #9
0
        private void button23_Click(object sender, EventArgs e)
        {
            FolderBrowserDialogEx CostumFolderBrowserDialog = new FolderBrowserDialogEx();
            string Titlu = "Alege Dosarul cu CGXML'uri";

            CostumFolderBrowserDialog.Title         = Titlu;
            CostumFolderBrowserDialog.StartPosition = FormStartPosition.CenterParent;
            DialogResult dr = CostumFolderBrowserDialog.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                PathFolder7   = true;
                textBox7.Text = CostumFolderBrowserDialog.SelectedPath;
            }
        }
예제 #10
0
 private void _btnMasterDirectory_Click(object sender, EventArgs e)
 {
     using (FolderBrowserDialogEx browseDlg = new FolderBrowserDialogEx())
     {
         browseDlg.ShowNewFolderButton   = true;
         browseDlg.ShowEditBox           = true;
         browseDlg.ShowFullPathInEditBox = true;
         browseDlg.Description           = "Select Master Forms Directory";
         browseDlg.RootFolder            = Environment.SpecialFolder.MyComputer;
         browseDlg.SelectedPath          = _txtMasterFormsDirectory.Text;
         if (browseDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             _txtMasterFormsDirectory.Text = browseDlg.SelectedPath;
         }
     }
 }
예제 #11
0
        private void AddSongsButtonClick(object sender, RoutedEventArgs e)
        {
            var dialog = new FolderBrowserDialogEx
            {
                Description = "Choose a folder containing the music that you want to add to the library"
            };

            dialog.ShowDialog();

            string selectedPath = dialog.SelectedPath;

            if (!String.IsNullOrEmpty(selectedPath))
            {
                this.mainViewModel.AddSongs(selectedPath);
            }
        }
예제 #12
0
        private void sourceOpenButton_Click(object sender, EventArgs e)
        {
            FolderBrowserDialogEx fbd = new FolderBrowserDialogEx();

            fbd.ShowNewFolderButton     = false;
            fbd.SelectedPath            = sourceInput.Text;
            fbd.ShowBothFilesAndFolders = true;
            fbd.DontIncludeNetworkFoldersBelowDomainLevel = true;



            if (fbd.ShowDialog() == DialogResult.OK)
            {
                sourceInput.Text = fbd.SelectedPath;
            }
        }
예제 #13
0
        //To display the browse dialog window (for selecting file/folder)
        private void browseSource_Click(object sender, EventArgs e)
        {
            var dlg1 = new FolderBrowserDialogEx();     //dlg1 is the object of 'FolderBrowserDialogEx.cs' file

            dlg1.Description             = "Select a File or Folder";
            dlg1.ShowNewFolderButton     = true;
            dlg1.ShowEditBox             = false;
            dlg1.ShowBothFilesAndFolders = true;
            dlg1.ShowFullPathInEditBox   = true;
            dlg1.RootFolder = System.Environment.SpecialFolder.MyComputer;

            // Show the FolderBrowserDialog.
            DialogResult result = dlg1.ShowDialog();

            if (result == DialogResult.OK)
            {
                Source.Text = dlg1.SelectedPath;
            }
        }
예제 #14
0
 private void _btnBrowseSrcFolder_Click(object sender, EventArgs e)
 {
     using (FolderBrowserDialogEx dlg = new FolderBrowserDialogEx())
     {
         dlg.Description           = "Select Source Folder";
         dlg.ShowNewFolderButton   = false;
         dlg.ShowEditBox           = true;
         dlg.ShowFullPathInEditBox = true;
         if (Directory.Exists(_txtSrcFolder.Text))
         {
             dlg.SelectedPath = _txtSrcFolder.Text;
         }
         if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             _txtSrcFolder.Text = dlg.SelectedPath;
         }
     }
     UpdateControls();
 }
예제 #15
0
        public static string OpenFolderBrowserDialog(string path = "")
        {
            string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            FolderBrowserDialogEx openPath = new FolderBrowserDialogEx()
            {
                Description           = "Choose a directory",
                ShowNewFolderButton   = false,
                SelectedPath          = Directory.Exists(path) ? path : desktop,
                ShowEditBox           = true,
                ShowFullPathInEditBox = true
            };
            DialogResult result = openPath.ShowDialog();

            if ((Directory.Exists(openPath.SelectedPath) || openPath.SelectedPath == desktop) && result == DialogResult.OK)
            {
                return(openPath.SelectedPath);
            }
            return(string.Empty);
        }
예제 #16
0
        private void button7_Click(object sender, EventArgs e)

        {
            FolderBrowserDialogEx CostumFolderBrowserDialog = new FolderBrowserDialogEx();
            string Titlu = "Alege Dosarul cu Titluri'uri";

            CostumFolderBrowserDialog.Title         = Titlu;
            CostumFolderBrowserDialog.StartPosition = FormStartPosition.CenterParent;

            DialogResult dr = CostumFolderBrowserDialog.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                FileNameFixer fixer = new FileNameFixer();
                fixer.StringReplacement = String.Empty;
                fixer.StringToRemove    = filePrefix.Text;
                fixer.FixAll(CostumFolderBrowserDialog.SelectedPath);
            }
        }
예제 #17
0
        private void btnCustom_Click(object sender, EventArgs e)
        {
            FolderBrowserDialogEx cfbd = new FolderBrowserDialogEx();

            cfbd.Title               = txtCaption.Text;
            cfbd.SelectedPath        = txtInitialFolder.Text;
            cfbd.ShowEditbox         = chkEditbox.Checked;
            cfbd.ShowNewFolderButton = chkShowNewFolderBtn.Checked;
            cfbd.RootFolder          = (Environment.SpecialFolder)comboRootFolder.SelectedValue;
            cfbd.StartPosition       = FormStartPosition.CenterScreen;

            DialogResult dr = cfbd.ShowDialog(this);

            txtRtnCode.Text   = dr.ToString();
            txtRtnFolder.Text = "";
            if (dr == DialogResult.OK)
            {
                txtRtnFolder.Text = cfbd.SelectedPath;
            }
        }
예제 #18
0
        private void btnSelectFolder_Click(object sender, RoutedEventArgs e)
        {
            string _folderName = IndexDirectory;

            var dlg1 = new FolderBrowserDialogEx
            {
                Description           = "Select a folder for the extracted files:",
                ShowNewFolderButton   = false,
                ShowEditBox           = true,
                SelectedPath          = _folderName,
                ShowFullPathInEditBox = false,
            };

            dlg1.RootFolder = System.Environment.SpecialFolder.MyComputer;
            System.Windows.Forms.DialogResult result = dlg1.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                SetIndexDirectory(dlg1.SelectedPath);
            }
        }
예제 #19
0
        public bool ShowDialog(IntPtr hWndOwner)
        {
            if ((Environment.OSVersion.Version.Major >= 6) && !this.UseOldDialog)
            {
                var    reflector = new Reflector("System.Windows.Forms");
                uint   num       = 0;
                var    type      = reflector.GetType("FileDialogNative.IFileDialog");
                object obj2      = reflector.Call(this.ofd, "CreateVistaDialog", new object[0]);
                reflector.Call(this.ofd, "OnBeforeVistaDialog", new object[] { obj2 });
                uint num2 = (uint)reflector.CallAs(typeof(FileDialog), this.ofd, "GetOptions", new object[0]);
                num2 |= (uint)reflector.GetEnum("FileDialogNative.FOS", "FOS_PICKFOLDERS");
                reflector.CallAs(type, obj2, "SetOptions", new object[] { num2 });
                object   obj3       = reflector.New("FileDialog.VistaDialogEvents", new object[] { this.ofd });
                object[] parameters = new object[] { obj3, num };
                reflector.CallAs2(type, obj2, "Advise", parameters);
                num = (uint)parameters[1];
                try
                {
                    int num3 = (int)reflector.CallAs(type, obj2, "Show", new object[] { hWndOwner });
                    return(0 == num3);
                }
                finally
                {
                    reflector.CallAs(type, obj2, "Unadvise", new object[] { num });
                    GC.KeepAlive(obj3);
                }
            }
            var ex = new FolderBrowserDialogEx();

            ex.Description           = this.Title;
            ex.SelectedPath          = this.InitialDirectory;
            ex.ShowNewFolderButton   = true;
            ex.ShowEditBox           = true;
            ex.ShowFullPathInEditBox = true;
            if (ex.ShowDialog(new WindowWrapper(hWndOwner)) != DialogResult.OK)
            {
                return(false);
            }
            ofd.FileName = ex.SelectedPath;
            return(true);
        }
예제 #20
0
        private void SelectFolderButton_Click(object sender, EventArgs e)
        {
            var dlg1 = new FolderBrowserDialogEx();

            dlg1.Description           = "Select a folder to extract to:";
            dlg1.ShowNewFolderButton   = true;
            dlg1.ShowEditBox           = true;
            dlg1.SelectedPath          = folderTextBox.Text;
            dlg1.ShowFullPathInEditBox = true;
            dlg1.RootFolder            = System.Environment.SpecialFolder.MyComputer;

            // Show the FolderBrowserDialog.
            DialogResult result = dlg1.ShowDialog();

            if (result == DialogResult.OK)
            {
                string url = dlg1.SelectedPath;
                folderTextBox.Text = url;
                label1.Text        = url.Substring(url.LastIndexOf("\\") + 1);
            }
        }
예제 #21
0
        private void ShowFolderBrowerDialog()
        {
            FolderBrowserDialogEx cfbd = new FolderBrowserDialogEx();

            cfbd.Title               = "导出资料";
            cfbd.SelectedPath        = Directory.Exists(this.ExportPath) ? this.ExportPath : Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            cfbd.ShowEditbox         = true;
            cfbd.ShowNewFolderButton = true;
            cfbd.RootFolder          = Environment.SpecialFolder.MyComputer;
            cfbd.StartPosition       = FormStartPosition.CenterScreen;
            cfbd.OKButtonCaption     = "确定";
            cfbd.CancelButtonCaption = "取消";
            cfbd.LblFolederText      = "路径";
            DialogResult dr = cfbd.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                this.edtPath.Text           = cfbd.SelectedPath;
                this.edtPath.SelectionStart = this.edtPath.Text.Length;
            }
        }
        private void txtMkvPath_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            FolderBrowserDialogEx folder = new FolderBrowserDialogEx
            {
                Title         = "locate mkvmerge.exe",
                ShowEditbox   = true,
                StartPosition = FormStartPosition.CenterParent
            };

            if (folder.ShowDialog(this) == DialogResult.OK)
            {
                if (!File.Exists(folder.SelectedPath + @"\mkvmerge.exe"))
                {
                    MessageBox.Show("mkvmerge.exe not Found!");
                }
                else
                {
                    txtMkvPath.Text = folder.SelectedPath;
                }
            }
        }
예제 #23
0
        public static bool GetAllPathes(out IEnumerable <string> pathes, string rootFolder)
        {
            if (rootFolder == string.Empty)
            {
                using (var fbd = new FolderBrowserDialogEx())
                {
                    fbd.ShowNewFolderButton = false;
                    var result = fbd.ShowDialog();
                    rootFolder = fbd.SelectedPath;
                    if (result != DialogResult.OK || String.IsNullOrWhiteSpace(rootFolder))
                    {
                        pathes = null;
                        return(false);
                    }
                }
            }

            pathes = DirSearch(rootFolder, ".jpg", ".png", ".jpeg");

            return(true);
        }
예제 #24
0
파일: Form1.cs 프로젝트: Spookspear/c-
        private void btnMine_Click(object sender, EventArgs e)
        {
            // 1gvb1 - need to set the properties I need and unstick them from the form

            FolderBrowserDialogEx cfbd = new FolderBrowserDialogEx();

            cfbd.Title               = "Please Select Folder ...";
            cfbd.SelectedPath        = "";
            cfbd.ShowEditbox         = true;
            cfbd.ShowNewFolderButton = false;
            cfbd.RootFolder          = Environment.SpecialFolder.Desktop;
            cfbd.StartPosition       = System.Windows.Forms.FormStartPosition.CenterScreen;

            DialogResult dr = cfbd.ShowDialog(this);

            txtRtnCode.Text   = dr.ToString();
            txtRtnFolder.Text = "";
            if (dr == DialogResult.OK)
            {
                txtRtnFolder.Text = cfbd.SelectedPath;
            }
        }
예제 #25
0
        private void bnAddIgFolder_Click(object sender, System.EventArgs e)
        {
            FolderBrowserDialogEx ignoreFolderBrowser = new FolderBrowserDialogEx
            {
                SelectedPath  = "",
                Title         = "Add New Ignore Folder...",
                ShowEditbox   = true,
                StartPosition = FormStartPosition.CenterScreen
            };

            if (lstFMIgnoreFolders.SelectedIndex != -1)
            {
                ignoreFolderBrowser.SelectedPath = TVSettings.Instance.IgnoreFolders[lstFMIgnoreFolders.SelectedIndex];
            }

            if (ignoreFolderBrowser.ShowDialog(this) == DialogResult.OK)
            {
                TVSettings.Instance.IgnoreFolders.Add(ignoreFolderBrowser.SelectedPath.ToLower());
                mDoc.SetDirty();
                FillFolderStringLists();
            }
        }
예제 #26
0
        private void selectFolderBtn_Click(object sender, EventArgs e)
        {
            string _folderName = "c:/";

            _folderName = (System.IO.Directory.Exists(defaultPathTextBox.Text)) ? _folderName : "";
            var dlg1 = new FolderBrowserDialogEx
            {
                Description         = "选择库目录:",
                ShowNewFolderButton = true,
                ShowEditBox         = true,
                //NewStyle = false,
                SelectedPath          = _folderName,
                ShowFullPathInEditBox = false,
            };

            dlg1.RootFolder = System.Environment.SpecialFolder.MyComputer;

            var result = dlg1.ShowDialog();

            if (result == DialogResult.OK)
            {
                defaultPathTextBox.Text = dlg1.SelectedPath;
            }
        }
예제 #27
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (this.listBox1.Visible != true)
            {
                this.listBox1.Visible = true;
            }
            string sector = "";
            //browse
            FolderBrowserDialogEx CostumFolderBrowserDialog = new FolderBrowserDialogEx();
            string Titlu = "Alege Dosarul cu CGXML'uri";

            CostumFolderBrowserDialog.Title         = Titlu;
            CostumFolderBrowserDialog.StartPosition = FormStartPosition.CenterParent;
            DialogResult dr = CostumFolderBrowserDialog.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                CostumFolderBrowserDialogPath = CostumFolderBrowserDialog.SelectedPath;
            }
            string[]        filez = Directory.GetFiles(CostumFolderBrowserDialogPath.ToString(), "*.cgxml", SearchOption.AllDirectories);
            NumericComparer ns    = new NumericComparer();

            System.Array.Sort(filez, ns);
            var files = filez.Select(x => new FileInfo(x)).ToArray();
            //initial vars
            string futureFieldName    = "ID";
            string futureFieldAreaCG  = "Sup Mas";
            string futureFieldLegalCG = "Sup Acte";
            string futurePerson       = "Persoana";
            int    nrCGXML            = 0;
            int    intr = 0;

            for (int i = 0; i < (int)files.Length; i++)
            {
                nrCGXML++;
            }
            //Create a future list
            IList <Feature> futuresList = new List <Feature>();

            //loop trough cgxml
            for (int i = 0; i < (int)files.Length; i++)
            {
                FileInfo fo     = files[i];
                CGXML    fisier = new CGXML();
                try
                {
                    fisier.ReadXml(fo.FullName);
                }
                catch (Exception exception)
                {
                    Exception ex = exception;
                    MessageBox.Show(string.Concat(new string[] { "Eroare ", ex.GetType().ToString(), "\n", ex.Message, fo.FullName }));
                }

                //create geometry factory
                IGeometryFactory geomFactory = NtsGeometryServices.Instance.CreateGeometryFactory();
                IGeometry[]      gr          = new IGeometry[nrCGXML];
                foreach (CGXML.LandRow lr in fisier.Land)
                {
                    var          r         = 0;
                    string       Person    = "";
                    var          q         = 0;
                    Coordinate[] myCoord   = new Coordinate[fisier.Points.Count + 1];
                    string[]     personArr = new string[fisier.Person.Count];
                    sector = lr.CADSECTOR.ToString();
                    foreach (CGXML.PointsRow pr in fisier.Points)
                    {
                        if (pr.IMMOVABLEID != 9898989)
                        {
                            myCoord[r++] = new Coordinate(pr.X, pr.Y);
                        }
                    }
                    if (myCoord[r - 1] != myCoord[0])
                    {
                        myCoord[r] = myCoord[0];
                    }

                    foreach (CGXML.PersonRow pp in fisier.Person)
                    {
                        personArr[q++] = string.Concat(pp.FIRSTNAME, " ", pp.LASTNAME);
                    }
                    //create the default table with fields - alternately use DBaseField classes
                    AttributesTable t = new AttributesTable();
                    t.AddAttribute(futureFieldName, lr.CADGENNO);
                    t.AddAttribute(futureFieldAreaCG, lr.MEASUREDAREA);
                    t.AddAttribute(futureFieldLegalCG, lr.PARCELLEGALAREA);
                    t.AddAttribute(futurePerson, personArr[0]);
                    //Geometry
                    myCoord  = myCoord.Where(c => c != null).ToArray();
                    gr[intr] = geomFactory.CreatePolygon(myCoord);
                    futuresList.Add(new Feature(gr[intr], t));
                    intr++;
                }
            }
            //Feature list
            IList <Feature>     features  = futuresList.OfType <Feature>().ToList();
            string              shapefile = string.Concat(CostumFolderBrowserDialogPath, "\\", "Imobile ", sector);
            ShapefileDataWriter writer    = new ShapefileDataWriter(shapefile)
            {
                Header = ShapefileDataWriter.GetHeader(features[0], features.Count)
            };

            writer.Write(features);

            System.Diagnostics.Process.Start("explorer.exe", CostumFolderBrowserDialogPath);
        }
예제 #28
0
    public static void Main()
    {
        //reference to the active project and the main window
        Form primaryMainForm = Program.ActiveProjectShell.PrimaryMainForm;

        if (primaryMainForm == null)
        {
            return;
        }

        SwissAcademic.Citavi.Project activeProject = Program.ActiveProjectShell.Project;
        if (activeProject == null)
        {
            return;
        }

        if (IsBackupAvailable() == false)
        {
            return;                                                                     //user wants to backup his/her project first
        }
        //if no reference filters applied, macro cannot operate
        if (Program.ActiveProjectShell.PrimaryMainForm.ReferenceEditorFilterSet.Filters.Count == 0)
        {
            string message = "This macro requires a selection of references to operate on.\r\n";
            message += "Please select some references with PDF files attached.";
            MessageBox.Show(message, "Citavi");
            return;
        }

        //path to the current project's CitaviFiles folder
        string citaviFilesPath = activeProject.GetFolderPath(CitaviFolder.CitaviFiles);

        List <Reference> references = Program.ActiveProjectShell.PrimaryMainForm.GetFilteredReferences();

        //List<Reference> references = CollectionUtility.ToList(activeProject.References);

        #region Generate list of file locations to move

        //first we create a list of files attached to the currently selected references,
        //having a PDF extension,
        //and existing inside the CitaviFiles folder
        List <FileMoveOperation> fileMoveOperations = new List <FileMoveOperation>();

        foreach (Reference reference in references)
        {
            foreach (Location location in reference.Locations)
            {
                if (location.LocationType != LocationType.ElectronicAddress)
                {
                    continue;
                }

                if (location.AddressUri.AddressInfo == ElectronicAddressInfo.CitaviFiles)
                {
                    if (Path.GetExtension(location.Address).Equals(".pdf", StringComparison.OrdinalIgnoreCase))
                    {
                        FileMoveOperation fileMoveOperation = new FileMoveOperation(location);
                        fileMoveOperations.Add(fileMoveOperation);
                        //MessageBox.Show(fileMoveOperation.SourcePath);
                        //MessageBox.Show(fileMoveOperation.OriginalFileName);
                    }
                }
            }
        }

        if (fileMoveOperations.Count == 0)
        {
            string message = string.Format("The {0} selected reference(s) do not have any PDF files attached, that are stored inside the CitaviFiles folder.", references.Count);
            MessageBox.Show(message, "Citavi");
            return;
        }

        #endregion Generate list of file locations to move

        #region Prompt user for target folder to move files to

        string targetFolderPath = string.Empty;

        using (FolderBrowserDialogEx folderBrowserDialog = new FolderBrowserDialogEx())
        {
            folderBrowserDialog.ShowNewFolderButton = false;
            folderBrowserDialog.Description         = string.Format("Select the folder where you want to move the {0} PDF files to.", fileMoveOperations.Count);
            folderBrowserDialog.SelectedPath        = Program.Settings.InitialDirectories.GetInitialDirectory(SwissAcademic.Citavi.Settings.InitialDirectoryContext.LocalFile, null);
            if (folderBrowserDialog.ShowDialog(primaryMainForm) == DialogResult.OK)
            {
                targetFolderPath = folderBrowserDialog.SelectedPath;
                //MessageBox.Show(targetFolderPath);
            }
            else
            {
                MessageBox.Show("Macro execution cancelled upon user's request.", "Citavi");
                return;
            }
        }

        #endregion Prompt user for target folder to move files to

        #region Copy the files to the new folder

        DirectoryInfo targetDirectory = new DirectoryInfo(targetFolderPath);

        foreach (FileMoveOperation fileMoveOperation in fileMoveOperations)
        {
            //avoid overwriting a possible existing file
            fileMoveOperation.TargetPath = Path2.GetUniqueFilePath(targetDirectory, fileMoveOperation.OriginalFileName);
            try
            {
                File.Copy(fileMoveOperation.SourcePath, fileMoveOperation.TargetPath, false);
                fileMoveOperation.CopySuccess = true;
            }
            catch (Exception exception)
            {
                fileMoveOperation.Errors.Add(exception);
                fileMoveOperation.CopySuccess = false;
            }
        }

        #endregion Copy the files to the new region

        #region Relink each reference to the new files

        foreach (FileMoveOperation fileMoveOperation in fileMoveOperations)
        {
            if (fileMoveOperation.CopySuccess)
            {
                try
                {
                    fileMoveOperation.TargetLocation       = fileMoveOperation.SourceLocation.Reference.Locations.Add(LocationType.ElectronicAddress, fileMoveOperation.TargetPath, string.Empty, false);
                    fileMoveOperation.TargetLocation.Notes = fileMoveOperation.SourceLocation.Notes;
                    fileMoveOperation.RelinkSuccess        = true;
                }
                catch (Exception exception)
                {
                    fileMoveOperation.Errors.Add(exception);
                    fileMoveOperation.RelinkSuccess = false;
                }
            }
        }

        #endregion Relink each reference to the new files

        #region Delete the original locations and move the files in the CitaviFiles folder to CitaviFiles\RecycleBin

        foreach (FileMoveOperation fileMoveOperation in fileMoveOperations)
        {
            if (fileMoveOperation.RelinkSuccess)
            {
                try
                {
                    Location locationToDelete = fileMoveOperation.SourceLocation;
                    Project  locationProject  = locationToDelete.Project;

                    if (locationToDelete == null)
                    {
                        continue;
                    }

                    ElectronicAddressUri addressUriToDelete = locationToDelete.AddressUri;
                    locationToDelete.Reference.Locations.Remove(locationToDelete);
                    Program.ActiveProjectShell.Save(primaryMainForm);


                    DirectoryInfo recycleBinDirectory = new DirectoryInfo(locationProject.GetFolderPath(CitaviFolder.RecycleBin));
                    string        deletedFilePath     = Path2.GetUniqueFilePath(recycleBinDirectory, fileMoveOperation.OriginalFileName);
                    File.Move(fileMoveOperation.SourcePath, deletedFilePath);

                    fileMoveOperation.DeleteSuccess = true;
                }
                catch (Exception exception)
                {
                    fileMoveOperation.Errors.Add(exception);
                    fileMoveOperation.DeleteSuccess = false;
                }
            }
        }

        #endregion Delete the original locations and move the files in the CitaviFiles folder to CitaviFiles\RecycleBin



        MessageBox.Show("Macro has finished execution.", "Citavi");
    }
 // Factory Methods
 public static FolderBrowserDialogEx PrinterBrowser()
 {
     FolderBrowserDialogEx x = new FolderBrowserDialogEx();
     // avoid MBRO comppiler warning when passing _rootFolderLocation as a ref:
     x.BecomePrinterBrowser();
     return x;
 }
예제 #30
0
        private void button4_Click(object sender, EventArgs e)
        {
            string raportname = "Validare Dosare-Fisiere";
            //Create new Excel Workbook
            HSSFWorkbook hssfworkbook = new HSSFWorkbook();

            //Create new Excel Sheet
            var sheet = hssfworkbook.CreateSheet(raportname);

            ////create a entry of DocumentSummaryInformation
            DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();

            dsi.Company = "OCPI MH";
            hssfworkbook.DocumentSummaryInformation = dsi;

            ////create a entry of SummaryInformation
            SummaryInformation si = PropertySetFactory.CreateSummaryInformation();

            si.Subject = "Export data from xml to xls using NPOI";
            hssfworkbook.SummaryInformation = si;


            //Create a header row
            string UAT           = "Padina";
            string Sector_Letter = "S";
            string Sector_NR     = "34";
            var    headerRow     = sheet.CreateRow(1);

            sheet.CreateRow(0).CreateCell(0).SetCellValue("UAT " + UAT);
            sheet.CreateRow(0).CreateCell(1).SetCellValue(string.Concat(Sector_Letter + Sector_NR));
            headerRow.CreateCell(0).SetCellValue("Dosar");
            headerRow.CreateCell(1).SetCellValue("Rezultat");


            //(Optional) freeze the header row so it is not scrolled
            //sheet.CreateFreezePane(0, 1, 0, 1);



            //Auto Filter
            //sheet.SetAutoFilter(new CellRangeAddress(0, 0, 0, 8));


            DataSet dsUAT        = new DataSet();
            DataSet dsLocality   = new DataSet();
            DataSet dsStreetType = new DataSet();

            dsUAT.ReadXml(string.Concat(Application.StartupPath.ToString(), "\\ProgramData\\Admin.xml"));
            dsLocality.ReadXml(string.Concat(Application.StartupPath.ToString(), "\\ProgramData\\Locality.xml"));
            dsStreetType.ReadXml(string.Concat(Application.StartupPath.ToString(), "\\ProgramData\\Dictionary.xml"));
            //

            FolderBrowserDialogEx CostumFolderBrowserDialog = new FolderBrowserDialogEx();
            string Titlu = "Alege Dosarul cu CGXML'uri";

            CostumFolderBrowserDialog.Title         = Titlu;
            CostumFolderBrowserDialog.StartPosition = FormStartPosition.CenterParent;

            DialogResult dr = CostumFolderBrowserDialog.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                //var
                string end1 = "_DATE_teren";
                string end2 = "Memoriu_tehnic";
                string end3 = "_Registru";
                string end4 = "_Opis";
                string end5 = "_Planuri_Cadastrale";
                string end6 = "shp";
                string end7 = "DXF";

                //rootfolder
                bool rootfolder;
                if (Directory.Exists(CostumFolderBrowserDialog.SelectedPath))
                {
                    rootfolder = true;
                }
                else
                {
                    rootfolder = false;
                }
                //cgxml
                bool cgxmlfolder;
                if (Directory.Exists(CostumFolderBrowserDialog.SelectedPath))
                {
                    cgxmlfolder = true;
                }
                else
                {
                    cgxmlfolder = false;
                }
                //sector cgxml
                bool sectorcgxml;
                if (Directory.Exists(CostumFolderBrowserDialog.SelectedPath))
                {
                    sectorcgxml = true;
                }
                else
                {
                    sectorcgxml = false;
                }
                //Date Teren
                bool DateTerenFolder;
                if (Directory.Exists(CostumFolderBrowserDialog.SelectedPath + "\\" + end1))
                {
                    DateTerenFolder = true;
                }
                else
                {
                    DateTerenFolder = false;
                }
                //Memoriu
                bool MemoriuTehnicFolder;
                if (Directory.Exists(CostumFolderBrowserDialog.SelectedPath + "\\" + end1 + "\\" + end2))
                {
                    MemoriuTehnicFolder = true;
                }
                else
                {
                    MemoriuTehnicFolder = false;
                }
                //Opis
                bool OpisFolder;
                if (Directory.Exists(CostumFolderBrowserDialog.SelectedPath + "\\" + end4))
                {
                    OpisFolder = true;
                }
                else
                {
                    OpisFolder = false;
                }
                //Sector Opis
                bool OpisSector;
                if (Directory.Exists(CostumFolderBrowserDialog.SelectedPath + "\\" + end4 + "\\" + Sector_Letter + Sector_NR))
                {
                    OpisSector = true;
                }
                else
                {
                    OpisSector = false;
                }
                //Planuri Cadastrale
                bool PlanCadFolder;
                if (Directory.Exists(CostumFolderBrowserDialog.SelectedPath + "\\" + end5))
                {
                    PlanCadFolder = true;
                }
                else
                {
                    PlanCadFolder = false;
                }
                //Shp Plan
                bool SHPFolder;
                if (Directory.Exists(CostumFolderBrowserDialog.SelectedPath + "\\" + end5 + "\\" + end6))
                {
                    SHPFolder = true;
                }
                else
                {
                    SHPFolder = false;
                }
                //PDF
                //Dxf Plan
                bool DXFFolder;
                if (Directory.Exists(CostumFolderBrowserDialog.SelectedPath + "\\" + end5 + "\\" + end7))
                {
                    DXFFolder = true;
                }
                else
                {
                    DXFFolder = false;
                }
                //PDF
                bool PDFFOLDER;
                if (Directory.Exists(CostumFolderBrowserDialog.SelectedPath))
                {
                    PDFFOLDER = true;
                }
                else
                {
                    PDFFOLDER = false;
                }
                //Reg
                bool RegistruFolder;
                if (Directory.Exists(CostumFolderBrowserDialog.SelectedPath + "\\" + end3))
                {
                    RegistruFolder = true;
                }
                else
                {
                    RegistruFolder = false;
                }
                //Reg sector
                bool RegistruSectorFolder;
                if (Directory.Exists(CostumFolderBrowserDialog.SelectedPath + "\\" + end3 + "\\" + Sector_Letter + Sector_NR))
                {
                    RegistruSectorFolder = true;
                }
                else
                {
                    RegistruSectorFolder = false;
                }
                string str1 = string.Concat(CostumFolderBrowserDialog.SelectedPath + "\\" + end3 + "\\" + Sector_Letter + Sector_NR);
                string str2 = string.Concat(UAT + end3);
                string str3 = string.Concat(Sector_Letter + Sector_NR);
                string str4 = string.Concat(UAT + end4);
                string test = UAT + end1;

                sheet.CreateRow(2).CreateCell(0).SetCellValue(str1);
                sheet.CreateRow(2).CreateCell(1).SetCellValue(DateTerenFolder);
                sheet.CreateRow(3).CreateCell(0).SetCellValue(end2);
                sheet.CreateRow(3).CreateCell(1).SetCellValue(MemoriuTehnicFolder);
                sheet.CreateRow(4).CreateCell(0).SetCellValue(str2);
                sheet.CreateRow(4).CreateCell(1).SetCellValue(RegistruFolder);
                sheet.CreateRow(5).CreateCell(0).SetCellValue(str3);
                sheet.CreateRow(5).CreateCell(1).SetCellValue(RegistruSectorFolder);
                sheet.CreateRow(6).CreateCell(0).SetCellValue(str4);
                sheet.CreateRow(6).CreateCell(1).SetCellValue(OpisFolder);
                sheet.CreateRow(7).CreateCell(0).SetCellValue(UAT + end5);
                sheet.CreateRow(7).CreateCell(1).SetCellValue(PlanCadFolder);
                sheet.CreateRow(8).CreateCell(0).SetCellValue(end6);
                sheet.CreateRow(8).CreateCell(1).SetCellValue(SHPFolder);
                sheet.CreateRow(9).CreateCell(0).SetCellValue(end7);
                sheet.CreateRow(9).CreateCell(1).SetCellValue(DXFFolder);



                //Write the stream data of workbook to the root directory

                FileStream file = new FileStream(string.Concat(CostumFolderBrowserDialog.SelectedPath, "\\", raportname, ".xls"), FileMode.Create);
                hssfworkbook.Write(file);
                file.Close();
                //MessageBox
                DoneMsgBox msg = new DoneMsgBox();
                msg.ShowDialog();

                if (msg.DialogResult == DialogResult.No)
                {
                    System.Diagnostics.Process.Start("explorer.exe", CostumFolderBrowserDialog.SelectedPath);
                }
                else if (msg.DialogResult == DialogResult.Yes)
                {
                    System.Diagnostics.Process.Start(CostumFolderBrowserDialog.SelectedPath + "/" + raportname + ".xls");
                }
            }
        }
예제 #31
0
파일: ThisAddIn.cs 프로젝트: Spookspear/c-
        public void readFolders(Excel.Workbook Wkb)
        {
            Excel.Worksheet Wks;            // instantiate worksheet object
            Wks = Wkb.ActiveSheet;          // point to active sheet

            // custom extended class for browsing folders

            // am needing a folder full of files that will take a while to load
            // how many files?
            //
            // C:\Temp\manyFiles-01
            string strPath;

            strPath = "C:\\Temp\\manyFiles-01";
            // strPath = "c:\\temp\\sfc"""

            FolderBrowserDialogEx cfbd = new FolderBrowserDialogEx()
            {
                Title               = "Please Select Folder ...",
                SelectedPath        = strPath,
                ShowEditbox         = true,
                ShowNewFolderButton = false,
                RootFolder          = Environment.SpecialFolder.Desktop,
                StartPosition       = FormStartPosition.CenterScreen
            };

            // need a yes or no for reading in extra details
            DialogResult dlgReadExtraDetails = askGetExtraDetails();
            bool         boolExtraDetails    = false;

            if (dlgReadExtraDetails == DialogResult.Yes)
            {
                boolExtraDetails = true;
            }

            if (dlgReadExtraDetails == DialogResult.No)
            {
                boolExtraDetails = false;
            }

            // Excel.XlEnableCancelKey.xlInterrupt

            string strWhichColumn = "F";

            if (dlgReadExtraDetails != DialogResult.Cancel)
            {
                if (cfbd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    DateTime dteStart = DateTime.Now;

                    int gintFileCount = 2;

                    // zap the sheet before we start
                    CommonExcelClasses.zapWorksheet(Wks, 1);

                    // string strPath = cfbd.SelectedPath;
                    directorySearch(cfbd.SelectedPath.ToString(), Wks, gintFileCount, boolExtraDetails, false);

                    writeHeaders(Wks, "FILES", boolExtraDetails);


                    DateTime dteEnd       = DateTime.Now;
                    int      milliSeconds = (int)((TimeSpan)(dteEnd - dteStart)).TotalMilliseconds;

                    Wks.Range[strWhichColumn + "1"].Value = milliSeconds + " milliSeconds";
                }
            }

            // MsgBox("Finished ...");
        }