AFFile Class
- Last UpdatedNov 18, 2025
- 7 minute read
- PI System
- AF SDK 2024 R2
- Developer
Inheritance Hierarchy
OSIsoft.AF.AssetAFFile
Namespace: OSIsoft.AF.Asset
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182
Syntax
[SerializableAttribute] public class AFFile : IComparable, IComparable<AFFile>, IEquatable<AFFile>
<SerializableAttribute> Public Class AFFile Implements IComparable, IComparable(Of AFFile), IEquatable(Of AFFile) Dim instance As AFFile
[SerializableAttribute] public ref class AFFile : IComparable, IComparable<AFFile^>, IEquatable<AFFile^>
[<SerializableAttribute>] type AFFile = class interface IComparable interface IComparable<AFFile> interface IEquatable<AFFile> end
The AFFile type exposes the following members.
Constructors
| Name | Description | |
|---|---|---|
| AFFile |
Initializes a new AFFile instance with default values that is not owned by another object.
| |
| AFFile(AFFile) |
This is the copy constructor which creates a new AFFile
object with the same values as the specified AFFile object.
| |
| AFFile(AFObject) |
Initializes a new AFFile instance with default values that is owned by
the specified AFObject.
|
Properties
| Name | Description | |
|---|---|---|
| Author |
The name of the person who last uploaded the file to the server.
| |
| ChangeDate |
The time the current file was last uploaded to the server.
| |
| Description |
Read/write property that provides a more detailed description of the object.
| |
| FileSize |
The size of the current file in bytes.
| |
| Name |
The name of the file.
| |
| Owner |
This read-only property is returns the AFObject that owns the AFFile.
| |
| Tag |
Gets or sets an object that provides additional data about the AFFile.
|
Methods
| Name | Description | |
|---|---|---|
| CompareTo(Object) |
Compares this instance with a specified Object.
| |
| CompareTo(AFFile) |
Compares this instance with a specified AFFile.
| |
| Delete |
Delete the file from the server.
| |
| Download |
Downloads the file from the server to a Stream.
| |
| Download(String) |
Downloads the file from the server to the specified path.
| |
| Equals(Object) |
Determines whether the specified Object is equal to the current object.
(Overrides ObjectEquals(Object).) | |
| Equals(AFFile) |
Indicates whether the current object is equal to another object of the same type.
| |
| GetHashCode |
Gets the hash code for this instance of the object which is suitable for use in hashing
algorithms and data structures like a hash table.
(Overrides ObjectGetHashCode.) | |
| GetType | Gets the Type of the current instance. (Inherited from Object.) | |
| ToString |
Returns a String that represents the current object.
(Overrides ObjectToString.) | |
| Upload(String) |
Uploads the file specified by the path to the server.
| |
| Upload(String, Stream) |
Uploads the Stream to the server with the specified name.
|
Operators
| Name | Description | |
|---|---|---|
| Equality |
The equality operator (==) compares its operands to determine if they are equal.
| |
| GreaterThan |
The greater than relation operator (>) compares its operands to determine
which one is greater than the other.
| |
| GreaterThanOrEqual |
The greater than or equal relation operator (>=) compares its operands to determine
which one is greater than or equal to the other.
| |
| Inequality |
The inequality operator (!=) compares its operands to determine if they are not equal.
| |
| LessThan |
The less than relation operator (<) compares its operands to determine
which one is less than the other.
| |
| LessThanOrEqual |
The less than or equal relation operator (<=) compares its operands to determine
which one is less than or equal to the other.
|
Remarks
The AFFile object contains the file header information and provides methods to load the actual file from the server and save the actual file to the server. An AFFile can be used as the value of an AFAttribute, an extended property, or an AFAnnotation.
Validation of the file size (FileMaxLength) and allowed extensions (FileAllowedExtensions) is performed when the file is saved to the server using one of the Upload Overload methods. These validation settings can be modified using the AFDiag utility. To disable all files, set the FileMaxLength to zero.
Examples
// This example demonstrates how to create an AFFile for an attribute // and extended property for an element and display information about it. // Get the Database PISystems myPISystems = new PISystems(); PISystem myPISystem = myPISystems.DefaultPISystem; AFDatabase myDB = myPISystem.Databases.DefaultDatabase; // Get the path to a file string path = Path.Combine(Path.GetTempPath(), "TestFile.txt"); using (File.Create(path)) { } // Create an Element AFElement myElement = myDB.Elements.Add("MyElement"); // Create an Attribute AFAttribute myAttribute = myElement.Attributes.Add("MyAttribute"); // Create an AFFile for the Attribute Value AFFile file = new AFFile(myAttribute); file.Upload(path); myAttribute.SetValue(file, null); // Display File Information Console.WriteLine("Name of File = {0}", file.Name); Console.WriteLine("Owner = {0}", file.Owner); // Download the File from the Server. file = myAttribute.GetValue().Value as AFFile; Stream fileStream = file.Download(); Console.WriteLine("Stream Size = {0}", fileStream.Length); // Create an AFFile for an ExtendedProperty Value file = new AFFile(); file.Upload(path); myElement.ExtendedProperties.Add("MyProperty", file); // Display File Information Console.WriteLine("Name of File = {0}", file.Name); Console.WriteLine("Owner = {0}", file.Owner);
' This example demonstrates how to create an AFFile for an attribute ' and extended property for an element and display information about it. ' Get the Database Dim myPISystems As New PISystems Dim myPISystem As PISystem = myPISystems.DefaultPISystem Dim myDB As AFDatabase = myPISystem.Databases.DefaultDatabase ' Get the path to a file Dim path As String = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "TestFile.txt") Dim fs As FileStream = System.IO.File.Create(path) fs.Close() ' Create an Element Dim myElement As AFElement = myDB.Elements.Add("MyElement") ' Create an Attribute Dim myAttribute As AFAttribute = myElement.Attributes.Add("MyAttribute") ' Create an AFFile for the Attribute Value Dim file As New AFFile(myAttribute) file.Upload(path) myAttribute.SetValue(file, Nothing) ' Display File Information Console.WriteLine("Name of File = {0}", file.Name) Console.WriteLine("Owner = {0}", file.Owner) ' Download the File from the Server. file = CType(myAttribute.GetValue().Value, AFFile) Dim fileStream As Stream = file.Download Console.WriteLine("Stream Size = {0}", fileStream.Length) ' Create an AFFile for an ExtendedProperty Value file = New AFFile file.Upload(path) myElement.ExtendedProperties.Add("MyProperty", file) ' Display File Information Console.WriteLine("Name of File = {0}", file.Name) Console.WriteLine("Owner = {0}", file.Owner)
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.