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

5.ImageDisplay.aspx
<%@ Page language="c#" Codebehind="ImageDisplay.aspx.cs" AutoEventWireup="false" Inherits="WebForm_Question2.ImageDisplay" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    
<HEAD>
        
<title>ImageDisplay</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">
            
<FONT face="宋体"></FONT>
        
</form>
    
</body>
</HTML>

6.ImageDisplay.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.Xml.XPath;
using System.IO;

namespace WebForm_Question2
{
    
/// <summary>
    
/// ImageDisplay 的摘要说明。
    
/// </summary>

    public class ImageDisplay : System.Web.UI.Page
    
{
        
private void Page_Load(object sender, System.EventArgs e)
        
{
            
// 在此处放置用户代码以初始化页面
          
                
string imageID=Request.QueryString["imageID"].ToString();
                
string fileName = Server.MapPath(".\\ImageList.xml");           
                XmlDocument doc 
= new XmlDocument();
                doc.Load(fileName);
                XmlNodeList nodelist 
= doc.SelectSingleNode("//image[imageID='"+imageID+"']").ChildNodes;
                
if(nodelist!=null)
                
{
                    
string imageData =nodelist.Item(4).InnerText;
                    
int imageSize = int.Parse(nodelist.Item(3).InnerText);
                    Response.OutputStream.Write(Convert.FromBase64String(imageData),
0,imageSize); 
                    Response.End();
                }

                
        
        }


        
Web 窗体设计器生成的代码
    }

}

posted @ 2006-09-18 08:55  青羽  阅读(1927)  评论(1编辑  收藏  举报