read and write binary xml
来源:互联网 发布:会计软件功能模块 编辑:程序博客网 时间:2024/05/17 02:56
将图片的二进制文件存入xml文件。
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
string imageFileName = @"C:/pic/lilies.jpg";
try
{
XmlTextWriter writer;
string strFilename = Server.MapPath("data1.xml") ;
writer = new XmlTextWriter(strFilename,Encoding.Default);
//Start writing the XML document
writer.Formatting = Formatting.Indented;
writer.WriteStartDocument();
writer.WriteStartElement("employee");
writer.WriteStartElement("image");
//Get the size of the file
FileInfo fi = new FileInfo(imageFileName);
int size = (int)fi.Length;
//Read the JPEG file
byte[] imgs = new byte[size];
FileStream fs = new FileStream(imageFileName,FileMode.Open);
BinaryReader reader = new BinaryReader(fs);
imgs = reader.ReadBytes(size);
reader.Close();
writer.WriteBase64(imgs, 0, size);
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
}
catch (Exception ex)
{
throw ex;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
读取二进制文件从xml文件。
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
string file = @"D:/UploadImage/abc.gif";
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("data1.xml"));
byte[] Img = Convert.FromBase64String(doc.SelectSingleNode("/employee/image").InnerText);
MemoryStream ms = new MemoryStream(Img);
Bitmap b = (Bitmap)System.Drawing.Image.FromStream(ms);
b.Save(file,System.Drawing.Imaging.ImageFormat.Gif);
#region 另一种方法创建文件
int length = Img.Length;
FileStream fs = new FileStream(file, FileMode.Create, FileAccess.Write);
fs.Write(Img, 0, length);
fs.Flush();
fs.Close();
#endregion
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- read and write binary xml
- Read and Write XML
- Qt Write and Read XML File 读写XML文件
- Read and Write Excel
- file read and write
- write and read
- read and write files
- Python read and write
- How To Read and Write XML Documents with GDataXML
- How To Read and Write XML Documents with GDataXML
- How To Read and Write XML Documents with GDataXML
- READ Write xml
- Read and write bytes data
- Read and Write File Code
- read and write '.bmp' file
- QT之write and read
- IO read and write. demo
- plist --- 's read and write
- 软件测试工程师的角色定位
- asp中使用图片验证码的方法
- Forget pcI Express, it's time for PCI Express 2!
- 破坏力超“熊猫烧香” 江民发布“小浩”蠕虫技术报告
- Win32汇编代码模板
- read and write binary xml
- 如何取得LPT端口打印机支持的 最小和最大页面大小
- tomcat服务&&远程桌面问题得到解决
- SPS2007数据结构分析一
- 使用POI操作Excel的方法
- powderdesigner高级应用
- PetShop4.0的消息处理
- [分享]MOSS2007管理与应用系列讲座
- php对oracle图片数据的存储和读取