xml保存图片和读取图片(一)

 

以下是我做过的一个利用xml保存图片和读取图片的小项目,项目名称:WebForm_Question2:

主页面:index.aspx
图片列表:ImageList.aspx
显示图片:ImagDisplay.aspx
xml文件:ImageList.xml
       

XML文件


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">&nbsp;&nbsp;&nbsp;
                        
<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="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        
</FONT>
                        
<asp:HyperLink id="HyperLink1" runat="server" NavigateUrl="ImageList.xml">查看XMl文件</asp:HyperLink></TD>
                
</TR>
            
</TABLE>
            
&nbsp;
        
</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 窗体设计器生成的代码
        
显示图片并读取其路径,大小
        
添加事件
        
添加图片信息到自定义的XML文件:ImageList.XML
    }

}

posted @ 2006-09-18 08:45  青羽  阅读(13144)  评论(2编辑  收藏  举报