LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Obtain the Extension and Friendly Name for a specific Document Format
#1
Posted
:
Tuesday, November 21, 2017 5:10:03 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 163
Was thanked: 9 time(s) in 9 post(s)
The DocumentWriter object contains static classes that can be used to obtain information about file formats and extensions. The DocumentWriter.GetFormatFileExtension() and DocumentWriter.GetFormatFriendlyName() methods can be used to obtain, respectively, the default extension and a user-friendly name for the specified format.
DocumentWriter.GetFormatFileExtension()DocumentWriter.GetFormatFriendlyName()The expected parameter is a value in the DocumentFormat enumeration. It is important to
note that DocumentFormat.User is a special case and only used under specific circumstances. As such, it is not a valid value to be used with either of these methods and an exception will be generated. For more information, see the documentation.
DocumentFormatCode:
var extension = DocumentWriter.GetFormatFileExtension(DocumentFormat.Docx);
var friendlyName = DocumentWriter.GetFormatFriendlyName(DocumentFormat.Docx);
This value of "extension" and "friendlyName" would be "docx" and "Microsoft Word" for this code snippet.
Here's one in which all extensions and friendly names can be printed to the console.
Code:
DocumentFormat[] docFormats = (DocumentFormat[])Enum.GetValues(typeof(DocumentFormat));
for (int i = 0; i < docFormats.Length; i++)
{
if (docFormats[i] == DocumentFormat.User)
continue;
var extension = DocumentWriter.GetFormatFileExtension(docFormats[i]);
var friendlyName = DocumentWriter.GetFormatFriendlyName(docFormats[i]);
Console.WriteLine(
"DocumentFormat:\t" + Enum.GetName(typeof(DocumentFormat),
docFormats[i]).PadRight(8) + "\tExtension: " + extension
+ "\tFriendlyName: " + friendlyName
);
}
Edited by moderator Friday, January 31, 2020 3:58:08 PM(UTC)
| Reason: Updated doc links to v20 and formatted sample code
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Obtain the Extension and Friendly Name for a specific Document Format
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.