FileConversionLibrary 1.6.0
dotnet add package FileConversionLibrary --version 1.6.0
NuGet\Install-Package FileConversionLibrary -Version 1.6.0
<PackageReference Include="FileConversionLibrary" Version="1.6.0" />
<PackageVersion Include="FileConversionLibrary" Version="1.6.0" />
<PackageReference Include="FileConversionLibrary" />
paket add FileConversionLibrary --version 1.6.0
#r "nuget: FileConversionLibrary, 1.6.0"
#:package FileConversionLibrary@1.6.0
#addin nuget:?package=FileConversionLibrary&version=1.6.0
#tool nuget:?package=FileConversionLibrary&version=1.6.0
File Conversion Library
A .NET library for converting CSV and XML files to various formats including XML, PDF, Word, JSON, and YAML. Now with enhanced Stream API and In-Memory conversion capabilities!
New Features in v1.5.0
- Stream API: Convert data directly from streams without temporary files (Currently In Testing Mode)
- In-Memory Conversion: Work with data objects directly in memory (Currently In Testing Mode)
- Advanced Options: Comprehensive configuration options for all formats
- Enhanced Performance: Optimized for large datasets
- Type-Safe Configuration: Strongly-typed options classes
Usage
Basic File Conversion (Original API)
// Create a new instance of the FileConverter
var fileConverter = new FileConverter();
CSV Conversions
// Convert CSV to PDF
await fileConverter.ConvertCsvToPdfAsync(
@"C:\Users\User\Desktop\csv_input.csv",
@"C:\Users\User\Desktop\output1.pdf"
);
// Convert CSV to JSON
await fileConverter.ConvertCsvToJsonAsync(
@"C:\Users\User\Desktop\csv_input.csv",
@"C:\Users\User\Desktop\output1.json"
);
// Convert CSV to Word
await fileConverter.ConvertCsvToWordAsync(
@"C:\Users\User\Desktop\csv_input.csv",
@"C:\Users\User\Desktop\output1.docx"
);
// Convert CSV to XML
await fileConverter.ConvertCsvToXmlAsync(
@"C:\Users\User\Desktop\csv_input.csv",
@"C:\Users\User\Desktop\output1.xml");
// Convert CSV to YAML
await fileConverter.ConvertCsvToYamlAsync(
@"C:\Users\User\Desktop\csv_input.csv",
@"C:\Users\User\Desktop\output1.yaml"
);
XML Conversions
// Convert XML to CSV
await fileConverter.ConvertXmlToCsvAsync(
@"C:\Users\User\Desktop\xml_input.xml",
@"C:\Users\User\Desktop\output2.csv"
);
// Convert XML to JSON
await fileConverter.ConvertXmlToJsonAsync(
@"C:\Users\User\Desktop\xml_input.xml",
@"C:\Users\User\Desktop\output2.json"
);
// Convert XML to PDF
await fileConverter.ConvertXmlToPdfAsync(
@"C:\Users\User\Desktop\xml_input.xml",
@"C:\Users\User\Desktop\output2.pdf"
);
// Convert XML to Word
await fileConverter.ConvertXmlToWordAsync(
@"C:\Users\User\Desktop\xml_input.xml",
@"C:\Users\User\Desktop\output2.docx"
);
// Convert XML to YAML
await fileConverter.ConvertXmlToYamlAsync(
@"C:\Users\User\Desktop\xml_input.xml",
@"C:\Users\User\Desktop\output2.yaml"
);
Stream API
For web applications, cloud services, and scenarios where you work with streams:
var fileConverter = new FileConverter();
// Convert from stream to stream
using var inputStream = File.OpenRead("input.csv");
var options = new ConversionOptions
{
SourceFormat = "csv",
TargetFormat = "json"
};
using var outputStream = await fileConverter.ConvertStreamAsync(inputStream, options);
// Convert stream to bytes (for HTTP responses)
var pdfBytes = await fileConverter.ConvertStreamToBytesAsync(inputStream, new ConversionOptions
{
SourceFormat = "csv",
TargetFormat = "pdf"
});
// Convert stream to string
var jsonString = await fileConverter.ConvertStreamToStringAsync(inputStream, new ConversionOptions
{
SourceFormat = "csv",
TargetFormat = "json"
});
Web API Example
[HttpPost("convert")]
public async Task<IActionResult> ConvertFile(IFormFile file, string targetFormat)
{
var options = new ConversionOptions
{
SourceFormat = "csv",
TargetFormat = targetFormat
};
using var inputStream = file.OpenReadStream();
var result = await fileConverter.ConvertStreamToBytesAsync(inputStream, options);
return File(result, GetMimeType(targetFormat), $"converted.{targetFormat}");
}
In-Memory API
Work directly with data objects for maximum performance and flexibility:
CSV In-Memory Conversions
var fileConverter = new FileConverter();
// Create CSV data in memory
{
Headers = new[] { "Name", "Age", "City" },
Rows = new List<string[]>
{
new[] { "John Doe", "25", "New York" },
new[] { "Jane Smith", "30", "London" }
}
};
// Convert to different formats with advanced options
var jsonOptions = new JsonConversionOptions
{
ConvertValues = true,
UseIndentation = true,
IncludeRowNumbers = true,
CreateNestedObjects = true,
NestedSeparator = ".",
ConvertArrays = true,
ArrayDelimiter = ";"
};
var json = fileConverter.ConvertCsvToJson(csvData, jsonOptions);
var pdfOptions = new PdfConversionOptions
{
FontSize = 12f,
Title = "Sales Report",
IncludeTimestamp = true,
AlternateRowColors = true,
LandscapeOrientation = true,
FontFamily = "Arial"
};
var pdfBytes = fileConverter.ConvertCsvToPdf(csvData, pdfOptions);
var wordOptions = new WordConversionOptions
{
UseTable = true,
FontFamily = "Calibri",
FontSize = 11,
AlternateRowColors = true,
PageOrientation = "Landscape"
};
var wordBytes = fileConverter.ConvertCsvToWord(csvData, wordOptions);
var xmlOptions = new XmlConversionOptions
{
OutputFormat = "Elements",
UseCData = true,
IncludeTimestamp = true,
NamingConvention = "CamelCase",
AddComments = true
};
var xml = fileConverter.ConvertCsvToXml(csvData, xmlOptions);
var yamlOptions = new YamlConversionOptions
{
Structure = "Dictionary",
NamingConvention = "CamelCase",
ConvertDataTypes = true,
IncludeComments = true,
SortKeys = true
};
var yaml = fileConverter.ConvertCsvToYaml(csvData, yamlOptions);
XML In-Memory Conversions
// Create XML data in memory
var xmlContent = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<products>
<product>
<Product>Laptop</Product>
<Price>999.99</Price>
<Category>Electronics</Category>
</product>
<product>
<Product>Book</Product>
<Price>29.99</Price>
<Category>Education</Category>
</product>
</products>";
var xmlData = new XmlData
{
Document = XDocument.Parse(xmlContent),
RootElementName = "products",
XmlVersion = "1.0",
Encoding = "UTF-8"
};
// Convert to different formats with advanced options
var csvOptions = new CsvConversionOptions
{
Delimiter = ';',
IncludeHeaders = true,
QuoteValues = true,
FlattenHierarchy = true,
IncludeAttributes = true
};
var csv = fileConverter.ConvertXmlToCsv(xmlData, csvOptions);
var jsonOptions = new JsonConversionOptions
{
ConvertValues = true,
UseIndentation = true,
RemoveWhitespace = true
};
var json = fileConverter.ConvertXmlToJson(xmlData, jsonOptions);
var pdfOptions = new PdfConversionOptions
{
Title = "Product Catalog",
FontSize = 10f,
AlternateRowColors = true,
IncludeTimestamp = true,
HierarchicalView = true
};
var pdf = fileConverter.ConvertXmlToPdf(xmlData, pdfOptions);
var wordOptions = new WordConversionOptions
{
UseTable = true,
FontFamily = "Calibri",
FontSize = 11,
FormatAsHierarchy = true,
AlternateRowColors = true
};
var word = fileConverter.ConvertXmlToWord(xmlData, wordOptions);
var yamlOptions = new YamlConversionOptions
{
Structure = "Dictionary",
ConvertDataTypes = true,
IncludeRootElement = true,
IncludeAttributes = true,
UseCamelCase = false,
SortKeys = true
};
var yaml = fileConverter.ConvertXmlToYaml(xmlData, yamlOptions);
Use Cases
Web Applications
// ASP.NET Core file upload and conversion
[HttpPost("upload-convert")]
public async Task<IActionResult> UploadAndConvert(IFormFile file)
{
using var stream = file.OpenReadStream();
var options = new ConversionOptions { SourceFormat = "csv", TargetFormat = "pdf" };
var result = await fileConverter.ConvertStreamToBytesAsync(stream, options);
return File(result, "application/pdf", "report.pdf");
}
Microservices
// Convert data received from another service
public async Task<string> ProcessDataFromService(HttpResponseMessage response)
{
using var stream = await response.Content.ReadAsStreamAsync();
var options = new ConversionOptions { SourceFormat = "xml", TargetFormat = "json" };
return await fileConverter.ConvertStreamToStringAsync(stream, options);
}
Data Processing Pipelines
// Process data in memory without file I/O
public byte[] GenerateReport(List<DataRecord> records)
{
var csvData = new CsvData
{
Headers = new[] { "ID", "Name", "Value" },
Rows = records.Select(r => new[] { r.Id, r.Name, r.Value.ToString() }).ToList()
};
return fileConverter.ConvertCsvToPdf(csvData, new PdfConversionOptions
{
Title = "Data Report",
IncludeTimestamp = true
});
}
Configuration Options
JsonConversionOptions
ConvertValues
: Auto-detect and convert data typesUseIndentation
: Pretty-print JSON outputIncludeRowNumbers
: Add row numbers to outputGroupByColumn
: Group data by specific columnCreateNestedObjects
: Support for nested object structuresConvertArrays
: Convert delimited values to arrays
PdfConversionOptions
FontSize
: Text font sizeTitle
: Document titleAlternateRowColors
: Zebra-striped rowsLandscapeOrientation
: Page orientationIncludeTimestamp
: Add generation timestamp
WordConversionOptions
UseTable
: Format as table vs. paragraphsFontFamily
&FontSize
: Typography settingsFormatAsHierarchy
: Hierarchical data representationAlternateRowColors
: Row styling
XmlConversionOptions
OutputFormat
: Elements, Attributes, Mixed, or HierarchicalUseCData
: Wrap content in CDATA sectionsNamingConvention
: Original, CamelCase, PascalCase, or SnakeCaseIncludeMetadata
: Add conversion metadata
YamlConversionOptions
Structure
: Array, Dictionary, Hierarchical, or GroupedConvertDataTypes
: Auto-detect data typesSortKeys
: Alphabetically sort keysIncludeComments
: Add descriptive comments
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Author
Bohdan Harabadzhyu
License
This project is licensed under the MIT License - see the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- CsvHelper (>= 33.1.0)
- DocumentFormat.OpenXml (>= 3.3.0)
- iTextSharp (>= 5.5.13.4)
- Newtonsoft.Json (>= 13.0.3)
- YamlDotNet (>= 16.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version 1.6.0:
- (Released: 6 August 2025) - Enhanced XML processing capabilities
- Added robust support for complex XML structures with nested elements
- Implemented proper handling of CDATA sections across all XML converters
- Added support for XML comments in output formats
- Enhanced handling of XML attributes and hierarchical structures
- Improved error handling for malformed XML documents
- Optimized performance for large XML documents with complex structures
- Added new configuration options for XML conversion customization
Version 1.5.0:
- (Released: 4 August 2025) - Major update with new APIs and enhanced functionality.
- Added Stream API for direct stream-to-stream conversions without temporary files (Currently In Testing Mode).
- Introduced In-Memory conversion API for working with data objects directly (Currently In Testing Mode).
- Added comprehensive strongly-typed options classes for all conversion types.
- Enhanced performance and memory efficiency for large dataset processing.
- Added support for web applications and microservices scenarios.
- Implemented advanced configuration options for all output formats.