New to Telerik Document ProcessingStart a free 30-day trial

Format Providers Manager

Updated on Apr 27, 2026

RadSpreadprocessing contains a WorkbookFormatProvidersManager class that allows you to specify a set of format providers and import or export files letting the manager choose the appropriate format provider. The class also exposes methods that return all registered providers and supported file extensions.

Registering and Unregistering Format Providers

The WorkbookFormatProvidersManager class contains two methods that allow you to register and unregister format providers respectively. The manager has the csv and txt format providers registered by default. The snippet in Example 1 illustrates how to register the XlsxFormatProvider.

Some Format Providers require additional package references. Check the full list of the FormatProviders' additional reference requirements in Format Providers - Additional package references.

Example 1: Register provider

C#
WorkbookFormatProvidersManager.RegisterFormatProvider(new XlsxFormatProvider());

You can also unregister format providers using the UnregisterFormatProvider() method. Example 2 demonstrates how to unregister the TxtFormatProvider.

Example 2: Unregister provider

C#
IWorkbookFormatProvider provider = WorkbookFormatProvidersManager.GetProviderByName("TxtFormatProvider");
if (provider != null)
{
	WorkbookFormatProvidersManager.UnregisterFormatProvider(provider);
}

Import

The format providers manager exposes an Import() method that takes two arguments:

  • string argument - specifies the extension of the file to be imported,
  • Stream argument - provides access to the file.

The method tries to find a registered format provider that can handle the extension of the file you would like to import, and if such a provider is registered the file is imported. If the manager does not have an appropriate format registered, an UnsupportedFileFormatException is thrown.

Example 3 demonstrates how to present the user with an OpenFileDialog and try to import the selected file. Note that you can use the GetOpenFileDialogFilter() method of the FileDialogHelper class to constructs the correct filter for all registered format providers.

Example 3: Import a file using OpenFileDialog

C#
OpenFileDialog openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
	try
	{
		string extension = Path.GetExtension(openFileDialog.SafeFileName);
		using (Stream input = openFileDialog.OpenFile())
		{
			workbook = WorkbookFormatProvidersManager.Import(extension, input, TimeSpan.FromSeconds(10));
		}
	}
	catch (IOException ex)
	{
		throw new IOException("The file cannot be opened. It might be locked by another application.", ex);
	}
}

The OpenFileDialog class exposes a different API in Silverlight. The name of the file could be obtained through the File.Name property of OpenFileDialog and the stream you can get using File.OpenRead().

You can achieve the same result through using the OpenFile command. In fact, the command executes exactly the same code as above. That said, make sure you register the format providers you would like to use before using the command.

Export

The format providers manager contains an Export() method that takes three arguments:

  • Workbook argument - the workbook to be exported
  • string argument - specifies the extension of the saved file
  • Stream argument - the Stream that will contain the data.

The method attempts to find a provider that can handle a file of the specified extension and if such a provider is registered, the file is saved. If the manager does not have an appropriate registered provider, an UnsupportedFileFormatException is raised.

Example 4 illustrates how to use the Export() method to save a file. The sample code presents the user with the SaveFileDialog. Note that here again you can use the GetOpenFileDialogFilter() method of the FileDialogHelper class to construct the correct filter for all registered format providers.

Example 4: Save a file using SaveFileDialog

C#
SaveFileDialog saveFileDialog = new SaveFileDialog();

if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
	string extension = Path.GetExtension(saveFileDialog.FileName);
	using (Stream output = saveFileDialog.OpenFile())
	{
		WorkbookFormatProvidersManager.Export(workbook, extension, output, TimeSpan.FromSeconds(10));
	}
}

You can achieve the same result through using the SaveFile command. In fact, the command executes exactly the same code as above. That said, make sure you register the format providers you would like to use before using the command.

Retrieve Registered Providers and Supported Extensions

Currently RadSpreadProcessing supports the following extensions: .xlsx, .xls, .csv, .txt, .json (export only) and .pdf (export only). The format providers available for them are respectively XlsxFormatProvider, XlsFormatProvider, CsvFormatProvider, TxtFormatProvider, JsonFormatProvider (export only) and PdfFormatProvider (export only).

The WorkbookFormatProvidersManager class offers several approaches to retrieve the registered format providers. The class offers the GetProviderByName() static method that searches through the registered providers to find a provider with a specific name. Also, the manager exposes the GetProvderByExtension extension. The class also contains a static method GetSupportedExtensions() that returns an IEnumerable of the currently supported file extensions.

For more examples and application scenarios of Importing and Exporting a Workbook to various formats using a FormatProvider check out the Import/Load and Export/Save RadSpreadProcessing Workbook knowledge base article.

See Also