dataset的压缩与传输
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;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.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();
object obj = brFormatter.Deserialize(memStream);
dataSetResult = (DataSet)obj;
return dataSetResult;
}
}
}
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;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.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();
object obj = brFormatter.Deserialize(memStream);
dataSetResult = (DataSet)obj;
return dataSetResult;
}
}
}
参考: http://www.cnblogs.com/davyjiang/articles/957244.html