Version

LoadFromXml(Stream) Method

Loads a layout from stream, including all properties.
Syntax
'Declaration
 
Public Overloads Sub LoadFromXml( _
   ByVal stream As Stream _
) 
public void LoadFromXml( 
   Stream stream
)

Parameters

stream
The stream to read.
Remarks

Invoking this method loads a layout, created by invoking the SaveAsXml(Stream) method, from a stream. The stream can be used to retrieve the Layout data from different sources, such as a file on disk, an Internet location or from memory.

The Clone and CopyFrom methods can be invoked to make a duplicate of a layout.

Example
Following code shows you how to save and load the saved layout in xml format. You can save the layout of an UltraGrid to a stream and later load it to the same UltraGrid or a different UltraGrid. Following code sample contains two button handlers. One has the code to save the layout to a file and the other one has the code to load the layout from a file.

Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinGrid

  Private XML_LAYOUT_FILE_PATH As String = "c:\\test.layout.xml"

  Private Sub Button92_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button92.Click

      ' Following code saves the ultraGrid1's layout to a file in xml format.
      Dim fs As System.IO.FileStream = Nothing

      Try
          ' Open a new file to save the layout to.
          fs = New System.IO.FileStream(XML_LAYOUT_FILE_PATH, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None)
      Catch exc As Exception
          MessageBox.Show(Me, XML_LAYOUT_FILE_PATH & " file not found. " & exc.Message, "Unable to open file", MessageBoxButtons.OK, MessageBoxIcon.Error)
          Return
      End Try

      ' Save the layout to the file in xml format.
      Me.UltraGrid1.DisplayLayout.SaveAsXml(fs, PropertyCategories.All)

      fs.Close()

  End Sub

  Private Sub Button93_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button93.Click

      ' Following code loads the saved layout from a file that was saved in xml format.

      Dim fs As System.IO.FileStream = Nothing

      Try
          ' Open the file where we saved the layout to in xml format.
          fs = New System.IO.FileStream(XML_LAYOUT_FILE_PATH, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)
      Catch exc As Exception

          MessageBox.Show(Me, XML_LAYOUT_FILE_PATH & " file not found. " & exc.Message, "Unable to open file", MessageBoxButtons.OK, MessageBoxIcon.Error)
          Return
      End Try

      ' Load the layout from the input stream by calling LoadFromXml method. It is very important 
      ' that you reset the Position of the file stream to where the layout data begins in case the 
      ' file stream has been read from previously.
      Me.UltraGrid1.DisplayLayout.LoadFromXml(fs, PropertyCategories.All)

      ' Close the file.
      fs.Close()

  End Sub
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;

private string XML_LAYOUT_FILE_PATH = "c:\\test.layout.xml";

private void button92_Click(object sender, System.EventArgs e)
{
	// Following code saves the ultraGrid1's layout to a file in xml format.
	System.IO.FileStream fs = null;
	
	try
	{
		// Open a new file to save the layout to.
		fs = new System.IO.FileStream( XML_LAYOUT_FILE_PATH, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None );
	}
	catch ( Exception exc )
	{
		MessageBox.Show( this, XML_LAYOUT_FILE_PATH + " file not found. " + exc.Message, "Unable to open file", MessageBoxButtons.OK, MessageBoxIcon.Error );
		return;
	}

	// Save the layout to the file in xml format.
	this.ultraGrid1.DisplayLayout.SaveAsXml( fs, PropertyCategories.All );

	fs.Close( );
}

private void button93_Click(object sender, System.EventArgs e)
{
	// Following code loads the saved layout from a file that was saved in xml format.

	System.IO.FileStream fs = null;
	
	try
	{
		// Open the file where we saved the layout to in xml format.
		fs = new System.IO.FileStream( XML_LAYOUT_FILE_PATH, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read );
	}
	catch ( Exception exc )
	{

		MessageBox.Show( this, XML_LAYOUT_FILE_PATH + " file not found. " + exc.Message, "Unable to open file", MessageBoxButtons.OK, MessageBoxIcon.Error );
		return;
	}

	// Load the layout from the input stream by calling LoadFromXml method. It is very important 
	// that you reset the Position of the file stream to where the layout data begins in case the 
	// file stream has been read from previously.
	this.ultraGrid1.DisplayLayout.LoadFromXml( fs, PropertyCategories.All );

	// Close the file.
	fs.Close( );
}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also