Hi, I want to delete PI historical data using AF SDK in C# code. Is it possible?
Yes, you can easily delete events using the AF SDK.
To delete events, you will need to call the UpdateValues method of either the AFData (when using a PIPoint DR) or PIPoint class using the AFUpdateMethod of "Remove". You will first need to build a list of events to delete.
Here's a quick example of deleting values using the AF SDK:
string piPointName = "sinusoid";
PISystems myPISystems = new PISystems();
PISystem myPISystem = myPISystems.DefaultPISystem;
PIServer myPIServer = new PIServers().DefaultPIServer;
PIPoint myPIPoint = PIPoint.FindPIPoint(myPIServer, piPointName);
AFTimeRange myTimeRange = new AFTimeRange();
myTimeRange.StartTime = DateTime.Now.AddHours(-1);
myTimeRange.EndTime = DateTime.Now;
//Find our events to delete
AFValues dataToDelete = myPIPoint.RecordedValues(myTimeRange, OSIsoft.AF.Data.AFBoundaryType.Inside, "", true, 0);
//delete them by using the remove option for the UpdateEvents. If possible, event deletes will be buffered and replicated to other collective members.
myPIPoint.UpdateValues(dataToDelete, OSIsoft.AF.Data.AFUpdateOption.Remove, OSIsoft.AF.Data.AFBufferOption.BufferIfPossible);
catch (Exception ex)
Console.WriteLine("Something went wrong reading or deleting events:" + ex.ToString());
Thanks a lot for the help
This will help me to do what i was expecting
Retrieving data ...