热门:网页模板.net视频教程JQueryMVCjsonExtJs源码示例三级联动JQuery菜单
您现在的位置:.Net中文社区>> XML编程>>正文内容

把图片流写入xml文件

发布时间:2008年12月22日点击数: 剑了
string xmlFile = Request.PhysicalApplicationPath + @"\1.xml";
            string imageFile = Request.PhysicalApplicationPath + @"\1.jpg";
string xmlFile = Request.PhysicalApplicationPath + @"\1.xml";
            string imageFile = Request.PhysicalApplicationPath + @"\1.jpg";
using (XmlWriter writer = XmlWriter.Create(xmlFile))
                {

                    writer.WriteStartDocument(false);
                    writer.WriteStartElement("employee");
                    writer.WriteAttributeString("id", "1");
                    writer.WriteStartElement("image");
                    writer.WriteAttributeString("fileName", imageFile);
                    FileInfo file = new FileInfo(imageFile);
                    int size = (int)file.Length;
                    byte[] imgBytes = new byte[size];
                    FileStream stream = new FileStream(imageFile, FileMode.Open);
                    BinaryReader reader = new BinaryReader(stream);
                    imgBytes = reader.ReadBytes(size);
                    reader.Close();
                    writer.WriteBinHex(imgBytes, 0, size);
                    writer.WriteEndElement();
                    writer.WriteEndElement();
                    writer.WriteEndDocument();
                    writer.Flush();
                }

本站热点业务

更多模板/案例展示

热门推荐

关于我们 | 联系我们 | 团队日志 | 网站地图 | 网站合作