FileInfoExtensionIsUtf8 Method

Tests whether the portion of the file specified by fileInfo that extends at least count characters from the beginning of the file is UTF-8 text. The method includes the byte order mark (BOM) in the check.

Definition

Namespace: FolkerKinzel.Strings
Assembly: FolkerKinzel.Strings (in FolkerKinzel.Strings.dll) Version: 9.4.0+10a7d4d71aa960998e32ac0ac6c4fcbe4164c917
C#
public static bool IsUtf8(
	this FileInfo fileInfo,
	int count = 255
)

Parameters

fileInfo  FileInfo
A FileInfo object that references the file to check.
count  Int32  (Optional)
The minimum number of characters to check. If the parameter is passed a negative number or if count is greater than the length of the data in the specified file, the entire file is checked. If 0 is passed to the parameter, the method only checks the byte order mark (BOM).

Return Value

Boolean
true if the checked file section represents UTF-8 text, false otherwise. In any case, if the method finds a UTF-8 BOM, it returns true. If count is 0 and no UTF-8 BOM is found, false is returned.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type FileInfo. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Exceptions

ArgumentNullExceptionfileInfo is null.
IOExceptionI/O error.

See Also