Dataset compression and transmission

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.