FileConversionLibrary 1.6.0

dotnet add package FileConversionLibrary --version 1.6.0
                    
NuGet\Install-Package FileConversionLibrary -Version 1.6.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FileConversionLibrary" Version="1.6.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FileConversionLibrary" Version="1.6.0" />
                    
Directory.Packages.props
<PackageReference Include="FileConversionLibrary" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FileConversionLibrary --version 1.6.0
                    
#r "nuget: FileConversionLibrary, 1.6.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FileConversionLibrary@1.6.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FileConversionLibrary&version=1.6.0
                    
Install as a Cake Addin
#tool nuget:?package=FileConversionLibrary&version=1.6.0
                    
Install as a Cake Tool

File Conversion Library

Image 1

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 types
  • UseIndentation: Pretty-print JSON output
  • IncludeRowNumbers: Add row numbers to output
  • GroupByColumn: Group data by specific column
  • CreateNestedObjects: Support for nested object structures
  • ConvertArrays: Convert delimited values to arrays

PdfConversionOptions

  • FontSize: Text font size
  • Title: Document title
  • AlternateRowColors: Zebra-striped rows
  • LandscapeOrientation: Page orientation
  • IncludeTimestamp: Add generation timestamp

WordConversionOptions

  • UseTable: Format as table vs. paragraphs
  • FontFamily & FontSize: Typography settings
  • FormatAsHierarchy: Hierarchical data representation
  • AlternateRowColors: Row styling

XmlConversionOptions

  • OutputFormat: Elements, Attributes, Mixed, or Hierarchical
  • UseCData: Wrap content in CDATA sections
  • NamingConvention: Original, CamelCase, PascalCase, or SnakeCase
  • IncludeMetadata: Add conversion metadata

YamlConversionOptions

  • Structure: Array, Dictionary, Hierarchical, or Grouped
  • ConvertDataTypes: Auto-detect data types
  • SortKeys: Alphabetically sort keys
  • IncludeComments: 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.