以下是我做过的一个利用xml保存图片和读取图片的小项目,项目名称:WebForm_Question2:
主页面:index.aspx
图片列表:ImageList.aspx
显示图片:ImagDisplay.aspx
xml文件:ImageList.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/safafmC4eV46VBhzStfEFuBteSNXxj1NjJAOevxosX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cEDKiI7QcVQsUTbjFo1y7HgFgFAH1NRe8klf1VSBwSR35/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/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIE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06UAXliRZHkCgO+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页面
1 using System; 2 using System.Collections; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Web; 7 using System.Web.SessionState; 8 using System.Web.UI; 9 using System.Web.UI.WebControls; 10 using System.Web.UI.HtmlControls; 11 using System.Xml; 12 using System.IO; 13 14 namespace WebForm_Question2 15 { 16 /// <summary> 17 /// index 的摘要说明。 18 /// </summary> 19 public class index : System.Web.UI.Page 20 { 21 protected System.Web.UI.WebControls.TextBox Txt_imginfo; 22 protected System.Web.UI.WebControls.Label Lab_size; 23 protected System.Web.UI.WebControls.Label Lab_imgpath; 24 protected System.Web.UI.WebControls.Image ImageSmall; 25 protected System.Web.UI.WebControls.Button btnUp_img; 26 protected System.Web.UI.HtmlControls.HtmlInputFile upImage; 27 28 protected string imagepath; 29 protected string imagesize; 30 protected System.Web.UI.WebControls.Button Btn_Add; 31 protected System.Web.UI.WebControls.Label Lab_message; 32 protected System.Web.UI.WebControls.HyperLink HyperLink2; 33 protected System.Web.UI.WebControls.HyperLink HyperLink1; 34 protected System.Web.UI.WebControls.Label Label1; 35 protected System.Web.UI.WebControls.Label Label2; 36 protected string imagetype; 37 38 private void Page_Load(object sender, System.EventArgs e) 39 { 40 // 在此处放置用户代码以初始化页面 41 } 42 43 #region Web 窗体设计器生成的代码 44 override protected void OnInit(EventArgs e) 45 { 46 // 47 // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 48 // 49 InitializeComponent(); 50 base.OnInit(e); 51 } 52 53 /// <summary> 54 /// 设计器支持所需的方法 - 不要使用代码编辑器修改 55 /// 此方法的内容。 56 /// </summary> 57 private void InitializeComponent() 58 { 59 this.btnUp_img.Click += new System.EventHandler(this.btnUp_img_Click); 60 this.Btn_Add.Click += new System.EventHandler(this.Btn_Add_Click); 61 this.Load += new System.EventHandler(this.Page_Load); 62 63 } 64 #endregion 65 #region 显示图片并读取其路径,大小 66 private void btnUp_img_Click(object sender, System.EventArgs e) 67 { 68 if(""!=upImage.PostedFile.FileName) 69 { 70 imagepath = upImage.PostedFile.FileName; 71 imagesize = upImage.PostedFile.ContentLength.ToString(); 72 imagetype = imagepath.Substring(imagepath.LastIndexOf(".")+1); 73 74 75 //判断是否是JPG或是GIF或是BMP或是PNG图片,可以任意修改图片类型,这里只是举例 76 if("jpg"!=imagetype && "gif"!=imagetype && "bmp"!=imagetype && "png"!=imagetype) 77 { 78 Response.Write("<script language='javascript'>alert('对不起,请选择JPG或是GIF或是BMP或是PNG图片!');</script>"); 79 return; 80 } 81 this.Lab_imgpath.Text = imagepath; 82 this.Lab_size.Text = imagesize; 83 this.ImageSmall.ImageUrl=imagepath; 84 } 85 } 86 #endregion 87 #region 添加事件 88 private void Btn_Add_Click(object sender, System.EventArgs e) 89 { 90 OP_Xml(); 91 } 92 #endregion 93 #region 添加图片信息到自定义的XML文件:ImageList.XML 94 private void OP_Xml() 95 { 96 XmlDocument doc = new XmlDocument(); 97 doc.Load(Server.MapPath("ImageList.XML")); 98 XmlNode root = doc.DocumentElement; 99 100 string id =Convert.ToString(Convert.ToInt32(root.LastChild.ChildNodes[0].InnerText)+1); 101 string path = this.Lab_imgpath.Text.Trim(); 102 string size = this.Lab_size.Text.Trim(); 103 string info = this.Txt_imginfo.Text.Trim(); 104 // 使用文件流构造一个二进制读取器将基元数据读作二进制值 105 FileStream fs = new FileStream(path,FileMode.Open); 106 BinaryReader br = new BinaryReader(fs); 107 byte[] imageBuffer = new byte[br.BaseStream.Length]; 108 br.Read(imageBuffer,0,Convert.ToInt32(br.BaseStream.Length)); 109 string textString = System.Convert.ToBase64String(imageBuffer); 110 fs.Close(); 111 br.Close(); 112 113 //创建元素节点 114 XmlNode image = doc.CreateElement("image"); 115 XmlNode imageid = doc.CreateElement("imageID"); 116 XmlNode imagepath = doc.CreateElement("imagepath"); 117 XmlNode imageinfo = doc.CreateElement("imageinfo"); 118 XmlNode imagesize = doc.CreateElement("imagesize"); 119 XmlNode imagedata = doc.CreateElement("imagedata"); 120 //创建文本节点 121 XmlNode txt_id = doc.CreateTextNode(id); 122 XmlNode txt_path = doc.CreateTextNode(path); 123 XmlNode txt_info = doc.CreateTextNode(info); 124 XmlNode txt_size = doc.CreateTextNode(size); 125 XmlNode txt_data = doc.CreateTextNode(textString); 126 //文本节点附加给元素节点 127 imageid.AppendChild(txt_id); 128 imagepath.AppendChild(txt_path); 129 imageinfo.AppendChild(txt_info); 130 imagesize.AppendChild(txt_size); 131 imagedata.AppendChild(txt_data); 132 //元素节点附加给image节点 133 image.AppendChild(imageid); 134 image.AppendChild(imagepath); 135 image.AppendChild(imageinfo); 136 image.AppendChild(imagesize); 137 image.AppendChild(imagedata); 138 //image节点附加给根节点 139 root.AppendChild(image); 140 doc.Save(Server.MapPath("ImageList.XML")); 141 this.Lab_message.Text = "图片添加成功!"; 142 } 143 #endregion 144 } 145 }
3.ImageList.aspx
1 <%@ Page language="c#" Codebehind="ImageList.aspx.cs" AutoEventWireup="false" Inherits="WebForm_Question2.ImageList" %> 2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 3 <HTML> 4 <HEAD> 5 <title>ImageList</title> 6 <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> 7 <meta name="CODE_LANGUAGE" Content="C#"> 8 <meta name="vs_defaultClientScript" content="JavaScript"> 9 <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> 10 </HEAD> 11 <body MS_POSITIONING="GridLayout"> 12 <form id="Form1" method="post" runat="server"> 13 <TABLE id="Table1" style="Z-INDEX: 102; LEFT: 152px; WIDTH: 694px; POSITION: absolute; TOP: 16px; HEIGHT: 240px" 14 cellSpacing="1" cellPadding="1" width="694" border="1"> 15 <TR> 16 <TD align="center" style="HEIGHT: 34px"> 17 <asp:Label id="Label1" runat="server" Width="128px" ForeColor="#000040" Font-Bold="True" Font-Size="Larger">图片列表页面</asp:Label></TD> 18 </TR> 19 <TR> 20 <TD style="HEIGHT: 155px"> 21 <asp:DataGrid id="DG_ImageList" runat="server" AutoGenerateColumns="False" Width="672px" BorderColor="#CCCCCC" 22 BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="3" Height="144px" AllowSorting="True" 23 AllowPaging="True" PageSize="5"> 24 <FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle> 25 <SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#669999"></SelectedItemStyle> 26 <ItemStyle ForeColor="#000066"></ItemStyle> 27 <HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#006699"></HeaderStyle> 28 <Columns> 29 <asp:BoundColumn DataField="imageID" HeaderText="图片ID"></asp:BoundColumn> 30 <asp:BoundColumn DataField="imagepath" HeaderText="图片路径"></asp:BoundColumn> 31 <asp:BoundColumn DataField="imageinfo" HeaderText="图片说明"></asp:BoundColumn> 32 <asp:BoundColumn DataField="imagesize" SortExpression="imagesize" HeaderText="图片大小"></asp:BoundColumn> 33 <asp:TemplateColumn> 34 <ItemTemplate> 35 <a href='ImageDisplay.aspx?imageID=<%# DataBinder.Eval(Container.DataItem,"imageID")%>'> 36 查看</a> 37 </ItemTemplate> 38 </asp:TemplateColumn> 39 </Columns> 40 <PagerStyle HorizontalAlign="Left" ForeColor="#000066" BackColor="White" Mode="NumericPages"></PagerStyle> 41 </asp:DataGrid></TD> 42 </TR> 43 <TR> 44 <TD><FONT face="宋体"> 45 <asp:HyperLink id="HyperLink2" runat="server" NavigateUrl="index.aspx">主页面</asp:HyperLink> 46 <asp:HyperLink id="HyperLink1" runat="server" NavigateUrl="ImageList.xml">查看XMl文件</asp:HyperLink> 47 </FONT> 48 </TD> 49 </TR> 50 </TABLE> 51 </form> 52 </body> 53 </HTML>
4.ImageList.aspx.cs
1 using System; 2 using System.Collections; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Web; 7 using System.Web.SessionState; 8 using System.Web.UI; 9 using System.Web.UI.WebControls; 10 using System.Web.UI.HtmlControls; 11 12 namespace WebForm_Question2 13 { 14 /// <summary> 15 /// ImageList 的摘要说明。 16 /// </summary> 17 public class ImageList : System.Web.UI.Page 18 { 19 protected System.Web.UI.WebControls.Label Label1; 20 protected System.Web.UI.WebControls.HyperLink HyperLink2; 21 protected System.Web.UI.WebControls.HyperLink HyperLink1; 22 protected System.Web.UI.WebControls.DataGrid DG_ImageList; 23 24 private void Page_Load(object sender, System.EventArgs e) 25 { 26 // 在此处放置用户代码以初始化页面 27 if(!IsPostBack) 28 { 29 ViewState["SortField"] = "imagesize"; //默认排序字段 30 BindDG(); 31 } 32 } 33 34 #region Web 窗体设计器生成的代码 35 override protected void OnInit(EventArgs e) 36 { 37 // 38 // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 39 // 40 InitializeComponent(); 41 base.OnInit(e); 42 } 43 44 /// <summary> 45 /// 设计器支持所需的方法 - 不要使用代码编辑器修改 46 /// 此方法的内容。 47 /// </summary> 48 private void InitializeComponent() 49 { 50 this.DG_ImageList.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DG_ImageList_PageIndexChanged); 51 this.DG_ImageList.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DG_ImageList_ItemDataBound); 52 this.DG_ImageList.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.DataGrid_Sort); 53 this.Load += new System.EventHandler(this.Page_Load); 54 55 } 56 #endregion 57 #region 将ImageList.xml文件绑定DataGrid中 58 private void BindDG() 59 { 60 DataSet ds = new DataSet(); 61 ds.ReadXml(Server.MapPath("ImageList.xml")); 62 63 DataView dv = (DataView)ds.Tables[0].DefaultView; 64 65 //设置排序的表达式 66 dv.Sort = SortField; 67 if (!SortAscending) 68 { 69 //定义默认的排序表达式 70 dv.Sort += " DESC"; 71 } 72 73 this.DG_ImageList.DataSource = ds.Tables[0]; 74 this.DG_ImageList.DataBind(); 75 } 76 #endregion 77 #region 排序事件处理程序 78 public void DataGrid_Sort(Object sender,DataGridSortCommandEventArgs e) 79 { 80 //对DataGrid排序 81 this.DG_ImageList.CurrentPageIndex = 0; 82 SortField = e.SortExpression; 83 84 BindDG(); //重新绑定数据 85 } 86 string SortField 87 { 88 get 89 { 90 object obj = ViewState["SortField"]; 91 if (obj == null) 92 { 93 return String.Empty; 94 } 95 return (string)obj; 96 } 97 98 set 99 { 100 if (value == SortField) 101 { 102 SortAscending = !SortAscending; 103 } 104 ViewState["SortField"] = value; 105 } 106 } 107 108 //排序方式 109 bool SortAscending 110 { 111 get 112 { 113 object obj = ViewState["SortAscending"]; 114 if (obj == null) 115 { 116 return true; 117 } 118 return (bool)obj; 119 } 120 set 121 { 122 ViewState["SortAscending"] = value; 123 } 124 } 125 126 #endregion 127 #region DataGrid分页事件 128 private void DG_ImageList_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e) 129 { 130 this.DG_ImageList.CurrentPageIndex = e.NewPageIndex; 131 BindDG(); 132 133 } 134 #endregion 135 #region 鼠标经过事件 136 private void DG_ImageList_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) 137 { 138 if ((e.Item.ItemType == ListItemType.Item) | (e.Item.ItemType == ListItemType.AlternatingItem) ) 139 { 140 e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#E4EDF9'"); 141 e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffffff'"); 142 } 143 } 144 #endregion 145 } 146 }
原文出处:当当网李燕平
http://www.cnblogs.com/tenghoo/archive/2006/09/18/507033.html