.NET API Browser

Microsoft .NET Documentation

Namespace: System.Net.Http.Headers

FileVersionHeaderValue

Represents the value of the File-Version HTTP header.

The File-Version header specifies the version of a file.

Constructors

Properties

Methods

Examples

Here's how you might use the FileVersionHeaderValue class:

using System.Net.Http.Headers;

var fileVersion = new FileVersionHeaderValue("1.0.0.0", "MyApp/2.0");
Console.WriteLine(fileVersion.ToString());
// Output: FileVersion/1.0.0.0, ProductVersion/2.0

var headerString = "FileVersion/1.2.3.4, ProductVersion/MyLib/1.5";
if (FileVersionHeaderValue.TryParse(headerString, out FileVersionHeaderValue parsedValue))
{
    Console.WriteLine($"Parsed File Version: {parsedValue.FileVersion}");
    Console.WriteLine($"Parsed Product Version: {parsedValue.ProductVersion}");
}
else
{
    Console.WriteLine("Failed to parse FileVersionHeaderValue.");
}

Remarks

The FileVersionHeaderValue class is immutable once created. It implements the ICloneable interface.

  • When parsing, the values for FileVersion and ProductVersion are treated as strings and can contain various characters.
  • The ToString() method formats the header value according to the HTTP specification for the File-Version header.
  • Use TryParse() for safe parsing to avoid exceptions when the input string is not in a valid format.

Syntax

Constructor

public FileVersionHeaderValue(string fileVersion, string productVersion)
Parameter Description
fileVersion The file version string. This parameter cannot be null or empty.
productVersion The product version string. This parameter can be null or empty.

Property

public string FileVersion { get; }
Type Description
string The file version string.

Property

public string ProductVersion { get; }
Type Description
string The product version string.

Method

public static FileVersionHeaderValue Parse(string input)
Parameter Description
input The string to parse.
Type Description
FileVersionHeaderValue A FileVersionHeaderValue instance created from the input string.

Exceptions

  • ArgumentNullException: Thrown if input is null.
  • FormatException: Thrown if input is not in a valid format.

Method

public static bool TryParse(string input, out FileVersionHeaderValue parsedValue)
Parameter Description
input The string to parse.
parsedValue When this method returns, contains the parsed FileVersionHeaderValue if the parse succeeded, or null otherwise.
Type Description
bool true if the string was parsed successfully; otherwise, false.

Method

public override string ToString()
Type Description
string The string representation of the header value.

Method

public override bool Equals(object obj)
Parameter Description
obj The object to compare with the current object.
Type Description
bool true if the specified object is equal to the current object; otherwise, false.

Method

public override int GetHashCode()
Type Description
int A hash code for the current object.

Method

public Type GetType()
Type Description
Type A Type instance representing the current object.

Method

protected object MemberwiseClone()
Type Description
object A shallow copy of the current object.