using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using Laserfiche.RepositoryAccess; namespace SearchAndEditMetadata { class Program { static void Main(string[] args) { #region Login, create connection RepositoryRegistration myRepoReg = new RepositoryRegistration("localhost", "LaserInvestigators"); Session mySession = new Session(); mySession.LogIn(myRepoReg); #endregion #region Get old investigator name, new investigator name Console.WriteLine("What's the old investigator name?"); string oldInvestigator = Console.ReadLine(); Console.WriteLine("What's the new investigator name?"); string newInvestigator = Console.ReadLine(); #endregion #region Create a search object, set the search, and do it using (Search mySearch = new Search(mySession)) { mySearch.Command = "{[]:[Investigator Assigned]=\"" + oldInvestigator + "\"}"; LongOperation longOp = mySearch.BeginRun(false); while (!longOp.IsCompleted) { Thread.Sleep(1000); longOp.Refresh(); //mySearch.UpdateStatus(); } // Set up the results to retrieve. SearchListingSettings settings = new SearchListingSettings(); settings.AddColumn(SystemColumn.Id); settings.AddColumn(SystemColumn.Name); settings.AddColumn(SystemColumn.CreationDate); // Update the Assigned To field for everyone. using (SearchResultListing results = mySearch.GetResultListing(settings)) { Console.WriteLine("The following results were updated:"); for (int k = 1; k <= results.RowsCount; k++) { int entryId = (int)results.GetDatum(k, SystemColumn.Id); Console.WriteLine(entryId + " " + results.GetDatumAsString(k, SystemColumn.Name)); EntryInfo myEntry = Entry.GetEntryInfo(entryId, mySession); FieldValueCollection myFields = myEntry.GetFieldValues(); myFields["Investigator Assigned"] = newInvestigator; myEntry.Lock(LockType.Exclusive); myEntry.SetFieldValues(myFields); myEntry.Save(); myEntry.Unlock(); myEntry.Dispose(); } } System.Console.WriteLine("Press return to exit..."); System.Console.ReadLine(); } #endregion #region Close out the connection and go home. mySession.Close(); #endregion } } }