Example #1
0
        private void SearchFiles(IEdmVault5 vault, object Val1)
        {
            try

            {
                IEdmSearch5 search = null;
                IEdmFolder5 folder = null;

                folder = vault.GetFolderFromPath(@"C:\CDI Controlled Documents\drawings\part drawings- controlled");

                search               = vault.CreateSearch();
                search.FileName      = "%.%d%w%";
                search.StartFolderID = folder.ID;

                object Var1  = "Part Numbers";
                object State = "Approved for Production";


                search.AddVariable(Var1, Val1);

                search.set_State(State);
                search.FindHistoricStates = false;
                search.Recursive          = true;

                String message = string.Empty;



                List <IEdmSearchResult5> results = new List <IEdmSearchResult5>();

                IEdmSearchResult5 result = search.GetFirstResult();

                while (result != null)

                {
                    results.Add(result);
                    result = search.GetNextResult();
                }
                results = results.Distinct(new SearchResultComparer()).ToList();
                if (results.Count < 1)
                {
                    search.Clear();
                    search.FileName      = Val1 + ".%d%w%";
                    search.StartFolderID = folder.ID;
                    State = "Approved for Production";
                    search.set_State(State);
                    search.FindHistoricStates = false;
                    search.Recursive          = true;

                    result = search.GetFirstResult();
                    while (result != null)

                    {
                        results.Add(result);
                        result = search.GetNextResult();
                    }
                    results = results.Distinct(new SearchResultComparer()).ToList();
                }
                foreach (IEdmSearchResult5 item in results)
                {
                    //get latest version
                    IEdmFile5   file      = null;
                    IEdmFolder5 retFolder = default(IEdmFolder5);
                    file = vault.GetFileFromPath(item.Path, out retFolder);
                    file.GetFileCopy(0);
                    //System.Diagnostics.Process.Start(item.Path, @"C:\Program Files\SOLIDWORKS Corp\eDrawings\eDrawings.exe");
                    //OpenEdwg(item.Path);
                    OpenSaveSldrwPdf(item.Path);



                    message = message + "Filename: " + item.Name + ", Rev: " + file.CurrentRevision + "; \n";
                }



                MessageBox.Show(message);
            }



            catch (Exception ex)

            {
                MessageBox.Show(ex.Message);
            }
        }