Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AF SDK Reference

AFFile Class

  • Last UpdatedNov 18, 2025
  • 7 minute read
AFFile Class
AFFile is used to represent a file object.

Inheritance Hierarchy

SystemObject
  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

  NameDescription
Public method
AFFile
Initializes a new AFFile instance with default values that is not owned by another object.
Public method
AFFile(AFFile)
This is the copy constructor which creates a new AFFile object with the same values as the specified AFFile object.
Public method
AFFile(AFObject)
Initializes a new AFFile instance with default values that is owned by the specified AFObject.

Properties

  NameDescription
Public property
Author
The name of the person who last uploaded the file to the server.
Public property
ChangeDate
The time the current file was last uploaded to the server.
Public property
Description
Read/write property that provides a more detailed description of the object.
Public property
FileSize
The size of the current file in bytes.
Public property
Name
The name of the file.
Public property
Owner
This read-only property is returns the AFObject that owns the AFFile.
Public property
Tag
Gets or sets an object that provides additional data about the AFFile.

Methods

  NameDescription
Public method
CompareTo(Object)
Compares this instance with a specified Object.
Public method
CompareTo(AFFile)
Compares this instance with a specified AFFile.
Public method
Delete
Delete the file from the server.
Public method
Download
Downloads the file from the server to a Stream.
Public method
Download(String)
Downloads the file from the server to the specified path.
Public method
Equals(Object)
Determines whether the specified Object is equal to the current object.
(Overrides ObjectEquals(Object).)
Public method
Equals(AFFile)
Indicates whether the current object is equal to another object of the same type.
Public method
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.)
Public method
GetType
Gets the Type of the current instance.
(Inherited from Object.)
Public method
ToString
Returns a String that represents the current object.
(Overrides ObjectToString.)
Public method
Upload(String)
Uploads the file specified by the path to the server.
Public method
Upload(String, Stream)
Uploads the Stream to the server with the specified name.

Operators

  NameDescription
Public operatorStatic member
Equality
The equality operator (==) compares its operands to determine if they are equal.
Public operatorStatic member
GreaterThan
The greater than relation operator (>) compares its operands to determine which one is greater than the other.
Public operatorStatic member
GreaterThanOrEqual
The greater than or equal relation operator (>=) compares its operands to determine which one is greater than or equal to the other.
Public operatorStatic member
Inequality
The inequality operator (!=) compares its operands to determine if they are not equal.
Public operatorStatic member
LessThan
The less than relation operator (<) compares its operands to determine which one is less than the other.
Public operatorStatic member
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.

Version Information

AFSDK


See Also

TitleResults for “How to create a CRG?”Also Available in