This documentation is archived and is not being maintained.

ResourceWriter.Generate Method

Saves all resources to the output stream in the system default format.

Namespace:  System.Resources
Assembly:  mscorlib (in mscorlib.dll)

public void Generate()

Implements

IResourceWriter.Generate()

ExceptionCondition
IOException

An I/O error occurred.

SerializationException

An error occurred during serialization of the object.

InvalidOperationException

This ResourceWriter has been closed and its Hashtable is unavailable.

Generate can only be called once, after all calls to AddResource have been made. If an exception occurs while writing the resources, the output stream is closed since the information written is most likely invalid.

Generate does not close the output stream in normal cases. Unless you are combining extra data with your .resources file or need access to the stream afterwards, you should call Close after calling Generate, or simply call Close.

The following code example uses the Generate method to write all resource objects in a ResourceWriter class to the output stream

using System;
using System.Resources;
using System.IO;
public class WriteResources 
{
   public static void Main(string[] args) 
   {  
       // Create a file stream to encapsulate items.resources.
       FileStream fs = new FileStream("items.resources", 
          FileMode.OpenOrCreate,FileAccess.Write);

       // Open a resource writer to write from the stream.
       IResourceWriter writer = new ResourceWriter(fs);

       // Add resources to the resource writer.
       writer.AddResource("String 1", "First String");
       writer.AddResource("String 2", "Second String");
       writer.AddResource("String 3", "Third String");

       // Generate the resources, and close the writer.
       writer.Generate();
       writer.Close();
    }
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: