Called when opening a document with persisted stream.

Namespace:  ESRI.ArcGIS.Desktop.AddIns

Assembly:  ESRI.ArcGIS.Desktop.Addins (in ESRI.ArcGIS.Desktop.Addins.dll) Version: 10.0.0.0 (10.0.0.0)

Syntax

C#
protected virtual void OnLoad(
	Stream inStrm
)
Visual Basic (Declaration)
Protected Overridable Sub OnLoad ( _
	inStrm As Stream _
)
Visual C++
protected:
virtual void OnLoad(
	Stream^ inStrm
)

Parameters

inStrm
Type: System.IO..::.Stream

The loaded persisted stream.

Remarks

Override this method to de-serialize the stream that was being saved in the document.

Examples

The code below shows an extension class that writes a private data structure which manages an ArcObjects type.
CopyC#
//  Need to add reference to ESRI.ArcGIS.ADF.Local assembly.
//  using System;
//  using System.Collections.Generic;
//  using System.IO;
//  using ESRI.ArcGIS.ADF.Serialization;
  public class LogExtension : ESRI.ArcGIS.Desktop.AddIns.Extension
  {
    private MyPersistentData _data;

    [Serializable()]
    private struct MyPersistentData
    {
      public string Location;
      public string UserName;
      public ESRI.ArcGIS.Geometry.PointClass Point;
    }

    public LogExtension()
    {
    }

    protected override void OnStartup()
    {
      ArcMap.Events.OpenDocument += new ESRI.ArcGIS.ArcMapUI.IDocumentEvents_OpenDocumentEventHandler(Events_OpenDocument);
    }

    protected override void OnShutdown()
    {
      _data.Point = null;
    }

    void Events_OpenDocument()
    {
      string logText = _data.Location + " ( " + _data.Point.X + ", " + _data.Point.Y + " )" + "\n UserName: " + _data.UserName;
      System.Windows.Forms.MessageBox.Show(logText);
    }

    protected override void OnSave(Stream outStrm)
    {
      //Get called when saving document.
      _data = new MyPersistentData();
      _data.Location = "Home";
      _data.UserName = Environment.UserName;
      _data.Point = new ESRI.ArcGIS.Geometry.PointClass();
      _data.Point.X = 100;
      _data.Point.Y = 200;

      PersistenceHelper.Save<MyPersistentData>(outStrm, _data);
    }

    protected override void OnLoad(Stream inStrm)
    {
      //Get called when opening a document with persisted stream.

      //Initialize the struct
      _data.Location = "";
      _data.Point = new ESRI.ArcGIS.Geometry.PointClass();
      PersistenceHelper.Load<MyPersistentData>(inStrm, ref _data);
    }
  }
CopyVB.NET
' Need to add reference to ESRI.ArcGIS.ADF.Local assembly. 
' using System; 
' using System.Collections.Generic; 
' using System.IO; 
' using ESRI.ArcGIS.ADF.Serialization; 
Public Class LogExtension
  Inherits ESRI.ArcGIS.Desktop.AddIns.Extension
  Private _data As MyPersistentData

  <Serializable()> _
  Private Structure MyPersistentData
    Public Location As String
    Public UserName As String
    Public Point As ESRI.ArcGIS.Geometry.PointClass
  End Structure

  Public Sub New()
  End Sub

  Protected Overloads Overrides Sub OnStartup()
    AddHandler ArcMap.Events.OpenDocument, AddressOf Events_OpenDocument
  End Sub

  Protected Overloads Overrides Sub OnShutdown()
    _data.Point = Nothing
  End Sub

  Private Sub Events_OpenDocument()
    Dim logText As String = (((_data.Location & " ( ") + _data.Point.X & ", ") + _data.Point.Y & " )" & vbLf & " UserName: ") + _data.UserName
    System.Windows.Forms.MessageBox.Show(logText)
  End Sub

  Protected Overloads Overrides Sub OnSave(ByVal outStrm As Stream)
    'Get called when saving document. 
    _data = New MyPersistentData()
    _data.Location = "Home"
    _data.UserName = Environment.UserName
    _data.Point = New ESRI.ArcGIS.Geometry.PointClass()
    _data.Point.X = 100
    _data.Point.Y = 200

    PersistenceHelper.Save(Of MyPersistentData)(outStrm, _data)
  End Sub

  Protected Overloads Overrides Sub OnLoad(ByVal inStrm As Stream)
    'Get called when opening a document with persisted stream. 


    'Initialize the struct 
    _data.Location = ""
    _data.Point = New ESRI.ArcGIS.Geometry.PointClass()
    PersistenceHelper.Load(Of MyPersistentData)(inStrm, _data)
  End Sub
End Class

See Also