This documentation is archived and is not being maintained.

ResourceWriter.AddResource Method

Adds a resource to the list of resources to be written.

Overload List

Adds a named resource specified as a byte array to the list of resources to be written.

[Visual Basic] Overloads Public Overridable Sub AddResource(String, Byte()) Implements IResourceWriter.AddResource
[C#] public virtual void AddResource(string, byte[]);
[C++] public: virtual void AddResource(String*, unsigned char __gc[]);
[JScript] public function AddResource(String, Byte[]);

Adds a named resource specified as an object to the list of resources to be written.

[Visual Basic] Overloads Public Overridable Sub AddResource(String, Object) Implements IResourceWriter.AddResource
[C#] public virtual void AddResource(string, object);
[C++] public: virtual void AddResource(String*, Object*);
[JScript] public function AddResource(String, Object);

Adds a String resource to the list of resources to be written.

[Visual Basic] Overloads Public Overridable Sub AddResource(String, String) Implements IResourceWriter.AddResource
[C#] public virtual void AddResource(string, string);
[C++] public: virtual void AddResource(String*, String*);
[JScript] public function AddResource(String, String);

Example

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of AddResource. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Imports System
Imports System.Resources
Imports System.IO

Public Class WriteResources
   
    Public Shared Sub Main(args() As String)
        ' Create a file stream to encapsulate items.resources.
        Dim fs As New FileStream("items.resources", _
           FileMode.OpenOrCreate, FileAccess.Write)
      
        ' Open a resource writer to write from the stream.
        Dim 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")
      
        ' Write the resources to the stream, and close it.
        writer.Close()
    End Sub

End Class

[C#] 
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");

        // Write the resources to the stream, and close it.
        writer.Close();
    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;
using namespace System::Resources;
using namespace System::IO;

int main() {
    // Create a file stream to encapsulate items.resources.
    FileStream* fs = new FileStream(S"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(S"String 1", S"First String");
    writer->AddResource(S"String 2", S"Second String");
    writer->AddResource(S"String 3", S"Third String");

    // Write the resources to the stream, and close it.
    writer->Close();
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

ResourceWriter Class | ResourceWriter Members | System.Resources Namespace

Show: