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


Save ToolbarControl Items to File Snippet (ArcObjects .NET 10.5 SDK)
ArcObjects Library Reference

Save ToolbarControl Items to File Snippet

Write a ToolbarControl items to a binary file on disk.

[C#]
///<summary>Write a ToolbarControl items to a binary file on disk.</summary>
///  
///<param name="toolbarControl"> An IToolbarControl2 interface. Use the .Object property when passing a control in .NET. Example: axToolbarControl1.Object</param>
///<param name="fileName">A System.String that is the location on disk where to write the ToolbarControl. Example: "C:\temp\myItems"</param>
///   
///<remarks>Call to save the ToolbarControl items out to a file. Typically this happens when an application exits and items are saved into a user local profile.</remarks>
public void SaveToolbarControlItemsToFile(ESRI.ArcGIS.Controls.IToolbarControl2 toolbarControl, System.String fileName)
{
  // Create a MemoryBlobStream 
  ESRI.ArcGIS.esriSystem.IBlobStream blobStream=new ESRI.ArcGIS.esriSystem.MemoryBlobStreamClass();

  // Get the IStream interface
  ESRI.ArcGIS.esriSystem.IStream stream=blobStream as ESRI.ArcGIS.esriSystem.IStream;

  // Save the ToolbarControl into the stream
  toolbarControl.SaveItems(stream);

  // Save the stream to a file
  blobStream.SaveToFile(fileName);
}
[Visual Basic .NET]
'''<summary>Write a ToolbarControl items to a binary file on disk.</summary>
'''  
'''<param name="toolbarControl"> An IToolbarControl2 interface. Use the .Object property when passing a control in .NET. Example: axToolbarControl1.Object</param>
'''<param name="fileName">A System.String that is the location on disk where to write the ToolbarControl. Example: "C:\temp\myItems"</param>
'''   
'''<remarks>Call to save the ToolbarControl items out to a file. Typically this happens when an application exits and items are saved into a user local profile.</remarks>
Public Sub SaveToolbarControlItemsToFile(ByVal toolbarControl As ESRI.ArcGIS.Controls.IToolbarControl2, ByVal fileName As System.String)

  ' Create a MemoryBlobStream
  Dim blobStream As ESRI.ArcGIS.esriSystem.IBlobStream=New ESRI.ArcGIS.esriSystem.MemoryBlobStreamClass()

  ' Get the IStream interface
  Dim stream As ESRI.ArcGIS.esriSystem.IStream=blobStream

  ' Save the ToolbarControl into the stream
  toolbarControl.SaveItems(stream)

  ' Save the stream to a file
  blobStream.SaveToFile(fileName)

End Sub

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Controls
  • ESRI.ArcGIS.System