Code
Using System;
Using System. collections;
Using System. configuration;
Using System. Data;
Using System. LINQ;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. htmlcontrols;
Using System. Web. UI. webcontrols;
Using System. Web. UI. webcontrols. webparts;
Using System. xml. LINQ;
UsingSystem. IO;
UsingSystem. runtime. serialization. formatters. Binary;
UsingSystem. runtime. serialization;
Namespace Testdemo. Web
{
Public Partial Class Default: system. Web. UI. Page
{
Protected Void Page_load ( Object Sender, eventargs E)
{
String Xmlurl = Server. mappath ( " Xmls/myxml. xml " );
Dataset DS = New Dataset ();
DS. readxml (xmlurl );
Byte [] DSB = Getbinaryformatdata (DS );
DS = Null ;
DS = Retrievedataset (DSB );
This. Rpthjcodes. datasource=DS;
This. Rpthjcodes. databind ();
}
/// </Summary>
/// <Param name = "dsoriginal"> </param>
/// <Returns> </returns>
Static Public Byte [] Getbinaryformatdata (Dataset dsoriginal)
{
Byte [] Binarydataresult = Null ;
Memorystream memstream = New Memorystream ();
Iformatter brformatter = New Binaryformatter ();
Dsoriginal. remotingformat = Serializationformat. Binary;
Brformatter. serialize (memstream, dsoriginal );
Binarydataresult = Memstream. toarray ();
Memstream. Close ();
Memstream. Dispose ();
Return Binarydataresult;
}
/**/
/// <Summary>
/// Retrieve dataset from data of binary format
/// </Summary>
/// <Param name = "binarydata"> </param>
/// <Returns> </returns>
Static Public Dataset retrievedataset ( Byte [] Binarydata)
{
Dataset datasetresult = Null ;
Memorystream memstream = New Memorystream (binarydata );
Iformatter brformatter = New Binaryformatter ();
ObjectOBJ=Brformatter. deserialize (memstream );
Datasetresult=(Dataset) OBJ;
ReturnDatasetresult;
}
}
}
Reference: http://www.cnblogs.com/davyjiang/articles/957244.html