Articles in this section
Category / Section

How to use the configuration file as an embedded resource in WinForms SyntaxEditor (EditControl) application?

1 min read

Adding configuration file

1. Include the configuration file - DefaultEditorConfig.xml in the project using the VS.NET designer and set its BuildAction property to Embedded Resource in the properties grid.

2. Use the following method to access the config file stream from the resources.

C#

private Stream LoadConfigFromResource(string configFileName)
{
    Assembly assembly;
    Stream configStream = null;
    try
    {
        assembly = Assembly.GetExecutingAssembly();
        configStream = (Stream)assembly.GetManifestResourceStream("SimpleEdit." + configFileName);
    }
    catch(Exception ex)
    {
       Console.WriteLine(ex.ToString());
    }
    return configStream;
}

 

VB

Private Function LoadConfigFromResource(ByVal configFileName As String) As Stream
    Dim assembly As Assembly
    Dim configStream As Stream = Nothing
    Try
        assembly = Assembly.GetExecutingAssembly()
        configStream = CType(assembly.GetManifestResourceStream("SimpleEdit." + configFileName), Stream)
    Catch ex As Exception
        Console.WriteLine(ex.ToString())
    End Try
    Return configStream
End Function

 

3. Apply the config file stream using the following code.

 

C#

Stream configStream = LoadConfigFromResource("DefaultEditorConfig.xml");
this.editControl1.Configurator.Open(configStream);
this.editControl1.ApplyConfiguration("C");

 

VB

Dim configStream As Stream = LoadConfigFromResource("DefaultEditorConfig.xml")
Me.editControl1.Configurator.Open(configStream)
Me.editControl1.ApplyConfiguration("C")

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied