
Using the ResXResourceWriter Class
You can use the ResXResourceWriter class to create a .resx file directly from code. The following example illustrates how to create a .resx file that stores a .jpg file as one of the resources inside the file. First, create the image using the Image.FromFile method. Next, create a ResXResourceWriter with a unique file name. Call the ResXResourceWriter.AddResource method for each image to add to the file. Finally, call the ResXResourceWriter.Close method to write the image information to the resource file and close the ResXResourceWriter.
|
Imports System
Imports System.Drawing
Imports System.Resources
Public Class SampleClass
Public Sub Main()
Dim img As Image
Dim rsxw As ResXResourceWriter
img = Image.FromFile("en-AU.jpg")
rsxw = new ResXResourceWriter("en-AU.resx")
rsxw.AddResource("en-AU.jpg",img)
rsxw.Close()
End Sub
End Class
|
|
using System;
using System.Drawing;
using System.Resources;
public class SampleClass
{
public static void Main()
{
Image img = Image.FromFile("en-AU.jpg");
ResXResourceWriter rsxw = new ResXResourceWriter("en-AU.resx");
rsxw.AddResource("en-AU.jpg",img);
rsxw.Close();
}
}
|
You can also manipulate a .resx file directly. However, to avoid corrupting the file, be careful not to modify any binary information that is stored in the file.
If you need to retrieve the names and values of the resources in a .resx file, use a ResXResourceReader. For a code example that demonstrates how to create a ResXResourceReader for a specified file, iterate through the file, and print out the names and values of resources, see the ResXResourceReader Class.
You cannot embed a .resx file in a runtime executable or compile it into a satellite assembly. You must convert your .resx file into a .resources file using the Resource File Generator (Resgen.exe). For more information, see Resources in .Resources File Format.