SerializerProvider.CreateSerializerWriter Method

Initializes an object derived from the abstract SerializerWriter class for the specified Stream that will use the specified descriptor.

Namespace:  System.Windows.Documents.Serialization
Assembly:  PresentationFramework (in PresentationFramework.dll)

public SerializerWriter CreateSerializerWriter(
	SerializerDescriptor serializerDescriptor,
	Stream stream
)

Parameters

serializerDescriptor
Type: System.Windows.Documents.Serialization.SerializerDescriptor
A SerializerDescriptor that contains serialization information for the SerializerWriter.
stream
Type: System.IO.Stream
The Stream to which the returned object writes.

Return Value

Type: System.Windows.Documents.Serialization.SerializerWriter
An object of a class derived from SerializerWriter.

ExceptionCondition
ArgumentNullException

One of the parameters is null.

ArgumentException

The serializerDescriptor is specifying the wrong version.

-or-

It is not registered.

-or-

The assembly file cannot be found.

-or-

The assembly cannot be loaded.

Only fully trusted applications can call CreateSerializerWriter.

The following example shows using CreateSerializerWriter to return a plug-in serialization writer for saving a file.


// Create a SerializerProvider for accessing plug-in serializers.
SerializerProvider serializerProvider = new SerializerProvider();

// Locate the serializer that matches the fileName extension.
SerializerDescriptor selectedPlugIn = null;
foreach ( SerializerDescriptor serializerDescriptor in
                serializerProvider.InstalledSerializers )
{
    if ( serializerDescriptor.IsLoadable &&
         fileName.EndsWith(serializerDescriptor.DefaultFileExtension) )
    {   // The plug-in serializer and fileName extensions match.
        selectedPlugIn = serializerDescriptor;
        break; // foreach
    }
}

// If a match for a plug-in serializer was found,
// use it to output and store the document.
if (selectedPlugIn != null)
{
    Stream package = File.Create(fileName);
    SerializerWriter serializerWriter =
        serializerProvider.CreateSerializerWriter(selectedPlugIn,
                                                  package);
    IDocumentPaginatorSource idoc =
        flowDocument as IDocumentPaginatorSource;
    serializerWriter.Write(idoc.DocumentPaginator, null);
    package.Close();
    return true;
}


.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2015 Microsoft