This document is archived and information here might be outdated.  Recommended version.


How to save ToolbarControl items to a settings file (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Building stand-alone applications > Using the Winforms ArcGIS Engine controls > Using the ToolbarControl > How to save ToolbarControl items to a settings file (ArcObjects .NET 10.6 SDK)

How to save ToolbarControl items to a settings file


Summary
This topic shows how to save the contents of a ToolbarControl to a settings file to preserve customizations made to the ToolbarControl by the end user.
An application typically loads the persisted contents back into the ToolbarControl at application start time and persists the contents of the ToolbarControl into a user's profile when an application exits.

Saving ToolbarControl items to a settings file

To save ToolbarControl items to a settings file, perform the following steps:
  1. Create a MemoryBlobStream and use the IToolbarControl.SaveItems method to save the items to that stream.
  2. Use the IBlobStream.SaveToFile method to save the stream to a settings file.

Loading ToolbarControl items from a settings file

To load ToolbarControl items from a settings file, perform the following steps: 
  1. Create a MemoryBlobStream and load the file using the IBlobStream.LoadFromFile method.
  2. Use the IToolbarControl2.LoadItems method to load the stream into the ToolbarControl.
The IToolbarControl2.LoadItems method replaces the existing contents of the ToolbarControl.
The following code example shows both scenarios:
[C#]
private void SaveToolbarControl(string filePath)
{
    //Create a MemoryBlobStream. 
    IBlobStream blobStream=new MemoryBlobStreamClass();
    //Get the IStream interface.
    IStream stream=(IStream)blobStream;
    //Get the IToolbarControl2 interface.
    IToolbarControl2 toolbarControl=(IToolbarControl2)axToolbarControl1.Object;
    //Save the ToolbarControl into the stream.
    toolbarControl.SaveItems(stream);
    //Save the stream to a file.
    blobStream.SaveToFile(filePath);
}

private void LoadToolbarControl(string filePath)
{
    if (System.IO.File.Exists(filePath) == true)
    {
        //Create a MemoryBlobStream.
        IBlobStream blobStream=new MemoryBlobStreamClass();
        //Load the stream from the file.
        blobStream.LoadFromFile(filePath);
        //Get the IStream interface.
        IStream stream=(IStream)blobStream;
        //Get the IToolbarControl2 interface.
        IToolbarControl2 toolbarControl=(IToolbarControl2)axToolbarControl1.Object;
        //Load the stream into the ToolbarControl.
        toolbarControl.LoadItems(stream);
    }
}
[VB.NET]
Private Sub SaveToolbarControl()
    'Create a MemoryBlobStream.
    Dim blobStream As IBlobStream
    blobStream=New MemoryBlobStreamClass
    'Get the IStream interface.
    Dim stream As IStream
    stream=blobStream
    'Get the IToolbarControl2 interface.
    Dim toolbarControl As IToolbarControl2
    toolbarControl=AxToolbarControl1.Object
    'Save the ToolbarControl into the stream.
    toolbarControl.SaveItems(stream)
    'Save the stream to a file.
    blobStream.SaveToFile(m_filePath)
End Sub


Private Sub LoadToolbarControl()
    If System.IO.File.Exists(m_filePath) Then
        'Create a MemoryBlobStream.
        Dim blobStream As IBlobStream
        blobStream=New MemoryBlobStreamClass
        'Load the stream from the file.
        blobStream.LoadFromFile(m_filePath)
        'Get the IStream interface.
        Dim stream As IStream
        stream=blobStream
        'Get the IToolbarControl2 interface.
        Dim toolbarControl As IToolbarControl2
        toolbarControl=AxToolbarControl1.Object
        'Load the stream into the ToolbarControl.
        toolbarControl.LoadItems(stream)
    End If
End Sub


See Also:

ToolbarControl class
IToolbarControl2 interface




To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
Engine Developer Kit Engine
ArcGIS for Desktop Basic
ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced