以下是我做过的一个利用xml保存图片和读取图片的小项目,项目名称:WebForm_Question2:
主页面:index.aspx
图片列表:ImageList.aspx
显示图片:ImagDisplay.aspx
xml文件:ImageList.xml
XML文件
<?xml version="1.0" encoding="utf-8"?>
<imagelist>
<image>
<imageID>1</imageID>
<imagepath>C:\Documents and Settings\Administrator\My Documents\image\新建文件夹\it1.jpg</imagepath>
<imageinfo>图片1</imageinfo>
<imagesize>3563</imagesize> <imagedata>/9j/4AAQSkZJRgABAQEASABIAAD//gApSW50ZWwoUikgSlBFRyBMaWJyYXJ5LCB2ZXJzaW9uIDEsNSw0LDM2/9sAQwAIBgYHBgUIBwcHCQkICgwUDQwLCwwZEhMPFB0aHx4dGhwcICQuJyAiLCMcHCg3KSwwMTQ0NB8nOT04MjwuMzQy/9sAQwEJCQkMCwwYDQ0YMiEcITIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy/8AAEQgAWgB4AwEiAAIRAQMRAf/EABsAAAIDAQEBAAAAAAAAAAAAAAQFAgMGAAEH/8QAPhAAAgEDAwIEBAMDCQkAAAAAAQIDAAQRBRIhMUEGEyJRYXGBoRQyQiOR0QcVUmKCscHh8CQlMzRDcpKi8f/EABkBAAIDAQAAAAAAAAAAAAAAAAECAwQFAP/EACgRAAICAQQBAwMFAAAAAAAAAAECABEDBBIhQVEFEzFh0fAicbHh8f/aAAwDAQACEQMRAD8A0emaFdafp8EUd/JBMEBkSNVMYbuACOlMUOuQgENY3S+zK0TH6jIpoqggZGasCg4HTFZ7MSbMlEWrqtzF/wA1o10oHVoGWUfbn7UTF4j0gtse5Nu5/TcIYz96LCEGpPGsilXVXHswyKWzGqXRTQ3C7oZY5VPdGBqYBGaTy+H9LlbcLKON/wCnCTGf3qRXi6TdQc2esXkYHRZtsy/fn711zqjkrXhXOTSU3ms2e4S/grsKobKq8TEH94/hRJ1hdzgwOAmMlfUO2Rx8/safafmC4eV46VBhzStfEFuBteSNXx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pnM2k4z5V1NcEDKiI7QcVQsUTbjFo1y7HgFgFAH1NRe8klf1VSBwSR35/PEx+p2FvfTtcGNYgf0p0FU2+hFX9CLxzuwa2ixXBPp0tBzt3O44PyokaRqaKZCtpHgZyQXonOo6mc2rBNhZmodOuSuPKXaP1leDzRc/nWkETxwRhd4WRuyA9D8eadw6VeXbqk16VG3cu1B0prbaMtqD5s7zjr+05FKc9cASRfU84NzKWNpbatqMazxLOCQHcMwCjHtnFaqHw1pdvgx2cYx/VqtJxEJPLgRMflwOlXR6lLsy+0HOBxSMSxuVM2b3W3VGUUKQLiMYUdBXUrbUpQ4AC47/HOK6loyCSl8woRC22U8IfZu33oLTLSKESRvFGCpxwBjI4P3om4JWJmUkEAkEduKhZcwxk8kjJP1NcfiMIyt40QAhVyfYUXvoWL8q1d2qKNJnDHkVT+Ft92/ykBPXipj8lTX8tCdPBGgx6RVmAOQAKj3qX8a6GCXNisgZ4wA/UjsaEHmSbY0eXf0Kt0FOFqIADscDOKcGKYnn3WVwwhQAiPdkjPPtXNfXKrJxkqBgbffvTk9Kjge1NcWJ/xR87Dqpj/M52dfaqzdSBGcRoDvxt2flHvTtgNx4FVOBzRBgiiS5ZSf2CsuR6gvxrqZkcV1MDOn/9k=</imagedata>
</image>
<image>
<imageID>2</imageID>
<imagepath>C:\Documents and Settings\Administrator\My Documents\image\新建文件夹\re.jpg</imagepath>
<imageinfo>图片2</imageinfo>
<imagesize>4937</imagesize>
<imagedata>/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCABeAIwDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQ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w7T5sIXy9r/eZiRtGf06UAXliRZHkCgO+NxHfHSpKx5Jb43M8aXEe9EVhGijK59c9fxK5xUdlqccFv5colzvZgw+YMCSeuffB9waAGSxQHVLi2DsjSqJTtPG7vx3P3TxyMnmqjW93b6sbh7l2tkUqTAfnTpncGzuGef4iO1dBc2FrfKDNEGI6N0I/EVQl0BZI/Ja8uGhYrvjkIfKgg7ckZxxQBQ1j7HNAb2HyJjGFkLJKCSRgKNuQDn37cYNdBZz/a7KC427fNQPj0yKZPYW80yTMm2ZOFkThgPTPpUdnaSW085ExeCTDKrfeVu/PcHj8c9c0AVJUuXmMEyw7n3MjEnD4AH547UyCC7im8mEojeXv55KZyBn1P+HpWxJCJJYmPWNiw/EEf1pqwbbt7gN99FRlx6E4P6mgCftWPdaHayv5rALg7vkhTOfXIGa2KrzI0+YllaMd9qgk/nn+VAGJaIjzzW8TSRwxphWjcpGT/AHCMnB+mKz4IJo75pUglWON8xeRIuCB94ZPzHjGecZ6V0v8AZVrHHtRNrH+Pqf1qtHpEUCRi0d423DLE5JGMnHYH6Dt6UAUL8aTHENrpNLKodTLKxV8988jPpmm6RHLDEkytLJHsCKQ5AYAtjpkE4IHbpVq00BbZi8otnk7SrCAxHfI6ela1vbJAWYKoZjyVGM/WgCSGUTRh1yM9jTmRWIJUHHqKUAAYAwKWgChpdqLayijZMOpbkjnqf6Yqr4iKDT1LmUfvkAaI4ZcnBOe3Hc8Vs1U1CAXNpJEzMoyGJU4J2kEjPvjFAGJEkL3E0rWQUmIbGeViXz90A+pOcnHGO4rS0i3WPTk8+NGlYkscDHXAx7YApllZ28saXUkQLSAuBk4CjOByeevTp+QrXoA//9k=</imagedata>
</image>
</imagelist>
1.:index.aspx页面
<%@ Page language="c#" Codebehind="index.aspx.cs" AutoEventWireup="false" Inherits="WebForm_Question2.index" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>index</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<TABLE id="Table1" style="Z-INDEX: 100; LEFT: 112px; WIDTH: 744px; POSITION: absolute; TOP: 48px; HEIGHT: 324px"
cellSpacing="1" cellPadding="1" width="744" border="1">
<TR>
<TD style="HEIGHT: 32px" colspan="2" align="center"><FONT face="宋体">
<asp:Label id="Label1" runat="server" Width="80px" ForeColor="#000040" Font-Bold="True" Font-Size="Larger">主页面</asp:Label></FONT></TD>
</TR>
<TR>
<TD style="WIDTH: 70px; HEIGHT: 32px">读取图片</TD>
<TD style="HEIGHT: 32px"><INPUT id="upImage" style="WIDTH: 328px; HEIGHT: 22px" type="file" size="35" name="File1"
runat="server">
<asp:Button id="btnUp_img" runat="server" Text="显示图片信息"></asp:Button></TD>
</TR>
<TR>
<TD style="WIDTH: 70px; HEIGHT: 20px">图片显示</TD>
<TD style="HEIGHT: 20px">
<asp:Image id="ImageSmall" runat="server"></asp:Image></TD>
</TR>
<TR>
<TD style="WIDTH: 70px; HEIGHT: 16px">图片路径</TD>
<TD style="HEIGHT: 16px">
<asp:Label id="Lab_imgpath" runat="server"></asp:Label></TD>
</TR>
<TR>
<TD style="WIDTH: 70px; HEIGHT: 5px">图片大小</TD>
<TD style="HEIGHT: 5px">
<asp:Label id="Lab_size" runat="server"></asp:Label></TD>
</TR>
<TR>
<TD style="WIDTH: 70px">图片说明</TD>
<TD>
<asp:TextBox id="Txt_imginfo" runat="server" TextMode="MultiLine" Width="645px" Height="144px"></asp:TextBox></TD>
</TR>
<TR>
<TD style="WIDTH: 70px"></TD>
<TD>
<asp:Button id="Btn_Add" runat="server" Text="添加图片信息到XML文件"></asp:Button>
<asp:Label id="Lab_message" runat="server" ForeColor="Red" Font-Bold="True"></asp:Label></TD>
</TR>
<TR>
<TD style="WIDTH: 70px"></TD>
<TD>
<asp:HyperLink id="HyperLink2" runat="server" NavigateUrl="ImageList.aspx">图片列表</asp:HyperLink><FONT face="宋体">
</FONT>
<asp:HyperLink id="HyperLink1" runat="server" NavigateUrl="ImageList.xml">查看XMl文件</asp:HyperLink></TD>
</TR>
</TABLE>
</form>
</body>
</HTML>
2.index.aspx.cs页面
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.IO;
namespace WebForm_Question2
{
/**//// <summary>
/// index 的摘要说明。
/// </summary>
public class index : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox Txt_imginfo;
protected System.Web.UI.WebControls.Label Lab_size;
protected System.Web.UI.WebControls.Label Lab_imgpath;
protected System.Web.UI.WebControls.Image ImageSmall;
protected System.Web.UI.WebControls.Button btnUp_img;
protected System.Web.UI.HtmlControls.HtmlInputFile upImage;
protected string imagepath;
protected string imagesize;
protected System.Web.UI.WebControls.Button Btn_Add;
protected System.Web.UI.WebControls.Label Lab_message;
protected System.Web.UI.WebControls.HyperLink HyperLink2;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected string imagetype;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnUp_img.Click += new System.EventHandler(this.btnUp_img_Click);
this.Btn_Add.Click += new System.EventHandler(this.Btn_Add_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
显示图片并读取其路径,大小#region 显示图片并读取其路径,大小
private void btnUp_img_Click(object sender, System.EventArgs e)
{
if(""!=upImage.PostedFile.FileName)
{
imagepath = upImage.PostedFile.FileName;
imagesize = upImage.PostedFile.ContentLength.ToString();
imagetype = imagepath.Substring(imagepath.LastIndexOf(".")+1);
//判断是否是JPG或是GIF或是BMP或是PNG图片,可以任意修改图片类型,这里只是举例
if("jpg"!=imagetype && "gif"!=imagetype && "bmp"!=imagetype && "png"!=imagetype)
{
Response.Write("<script language='javascript'>alert('对不起,请选择JPG或是GIF或是BMP或是PNG图片!');</script>");
return;
}
this.Lab_imgpath.Text = imagepath;
this.Lab_size.Text = imagesize;
this.ImageSmall.ImageUrl=imagepath;
}
}
#endregion
添加事件#region 添加事件
private void Btn_Add_Click(object sender, System.EventArgs e)
{
OP_Xml();
}
#endregion
添加图片信息到自定义的XML文件:ImageList.XML#region 添加图片信息到自定义的XML文件:ImageList.XML
private void OP_Xml()
{
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("ImageList.XML"));
XmlNode root = doc.DocumentElement;
string id =Convert.ToString(Convert.ToInt32(root.LastChild.ChildNodes[0].InnerText)+1);
string path = this.Lab_imgpath.Text.Trim();
string size = this.Lab_size.Text.Trim();
string info = this.Txt_imginfo.Text.Trim();
// 使用文件流构造一个二进制读取器将基元数据读作二进制值
FileStream fs = new FileStream(path,FileMode.Open);
BinaryReader br = new BinaryReader(fs);
byte[] imageBuffer = new byte[br.BaseStream.Length];
br.Read(imageBuffer,0,Convert.ToInt32(br.BaseStream.Length));
string textString = System.Convert.ToBase64String(imageBuffer);
fs.Close();
br.Close();
//创建元素节点
XmlNode image = doc.CreateElement("image");
XmlNode imageid = doc.CreateElement("imageID");
XmlNode imagepath = doc.CreateElement("imagepath");
XmlNode imageinfo = doc.CreateElement("imageinfo");
XmlNode imagesize = doc.CreateElement("imagesize");
XmlNode imagedata = doc.CreateElement("imagedata");
//创建文本节点
XmlNode txt_id = doc.CreateTextNode(id);
XmlNode txt_path = doc.CreateTextNode(path);
XmlNode txt_info = doc.CreateTextNode(info);
XmlNode txt_size = doc.CreateTextNode(size);
XmlNode txt_data = doc.CreateTextNode(textString);
//文本节点附加给元素节点
imageid.AppendChild(txt_id);
imagepath.AppendChild(txt_path);
imageinfo.AppendChild(txt_info);
imagesize.AppendChild(txt_size);
imagedata.AppendChild(txt_data);
//元素节点附加给image节点
image.AppendChild(imageid);
image.AppendChild(imagepath);
image.AppendChild(imageinfo);
image.AppendChild(imagesize);
image.AppendChild(imagedata);
//image节点附加给根节点
root.AppendChild(image);
doc.Save(Server.MapPath("ImageList.XML"));
this.Lab_message.Text = "图片添加成功!";
}
#endregion
}
}