aps.net 读取xml文件 并用smartpart包装 用于moss2007

 

using  System;
using  System.Data;
using  System.Configuration;
using  System.Collections;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Web.UI.HtmlControls;


public  partial  class  CallBack_UCCallback : System.Web.UI.UserControl
{
    
public string PageName = "";
    ArrayList al 
= new ArrayList();
    
string _ltdName = string.Empty;

    
private void Page_Load(object sender, System.EventArgs e)
    
{
        
if (!Page.IsPostBack)
        
{
            al.Add(
"gse");
            al.Add(
"gsed");
            al.Add(
"gsei");
            al.Add(
"gswg");
            al.Add(
"gswm");
            al.Add(
"Default");
        }

        _ltdName 
= System.IO.Path.GetFileName(Request.PhysicalPath);
        
//_ltdName = Request.PhysicalPath;
        _ltdName = _ltdName.Substring(0, _ltdName.LastIndexOf('.'));
        
if (al.Contains(_ltdName))
        
{
            
//PageName = _ltdName.Replace(".aspx", "A.xml");
            PageName = _ltdName+"A.xml";
            PopulateProductInfo(
"100");
        }

        
else
        
{
            
//PageName =al[0].ToString()+".xml";
            PageName = "products.xml";
            PopulateProductInfo(
"100"); 
        }

    }


    
public void CallBack1_Callback(object sender, ComponentArt.Web.UI.CallBackEventArgs e)
    
{
        
// Thread.Sleep simulates the experience of accessing a remote server 
        
// Remove before going to production 
        System.Threading.Thread.Sleep(200);
        PopulateProductInfo(e.Parameter);
        PlaceHolder1.RenderControl(e.Output);
    }


    
private void PopulateProductInfo(string ProductId)
    
{
        DataRow dr 
= getDataRow(ProductId);
        
if (dr != null)
        
{
            imgProductImage.ImageUrl 
= "../Test/SiteMap/" + dr["Image"].ToString();
            lblProductTitle.Text 
= dr["Title"].ToString();
            lblProductTagLine.Text 
= dr["TagLine"].ToString();
            lblProductInfo.Text 
= dr["ProductInfo"].ToString();
        }

    }


    
private DataRow getDataRow(string ProductId)
    
{
        
try
        
{
            DataSet ds 
= new DataSet();
            ds.ReadXml(Server.MapPath(
"../Test/SiteMap/" + PageName));
            
foreach (DataRow dr in ds.Tables[0].Rows)
            
{
                
if (dr["ProductId"].ToString() == ProductId)
                
{
                    
return dr;
                }

            }

        }

        
catch
        
{
            Response.Write(
"不存在" + PageName + "这个文件");
        }

        
return null;
    }

}



 

<% @ Control Language = " C# "  AutoEventWireup = " true "  CodeFile = " UCCallback.ascx.cs "  Inherits = " CallBack_UCCallback "   %>
<% @ Register Assembly = " ComponentArt.Web.UI, Version=2006.1.1231.1, Culture=neutral, PublicKeyToken=2683aeee0dd38d57 "
    Namespace
= " ComponentArt.Web.UI "  TagPrefix = " ComponentArt "   %>
         
< script type = " text/javascript " >
    
//  Image preloading
    var img1  =   new  Image();
    img1.src 
=   ' ../Test/SiteMap/spinner.gif ' ;
    function selectProduct(param)
    
{
      UCCallback1_CallBack1.Callback(param); 
    }

         
</ script >
   
< table cellspacing = " 0 "  cellpadding = " 0 "  border = " 0 "  style = " color:#666666; "   >
      
< tr >
        
< td >< table cellspacing = " 0 "  cellpadding = " 0 "  border = " 0 "  style = " color:#666666; "   >
    
< tr >
      
< td style = " font-size:13px; "  valign = " top " >< br >< br >       
        
< table cellspacing = " 0 "  cellpadding = " 2 "  border = " 0 " >
        
< tr >
          
< td >< img src = " ../Test/SiteMap/chevron.gif "  width = " 12 "  height = " 8 "  border = " 0 " ></ td >
          
< td style = " font-size:12px; width: 53px; " >< a href = " javascript:selectProduct('100'); "  title = " 业务概况 " > 业务概况 </ a ></ td >
        
</ tr >
        
< tr >
          
< td >< img src = " ../Test/SiteMap/chevron.gif "  width = " 12 "  height = " 8 "  border = " 0 " ></ td >
          
< td style = " font-size:12px; width: 53px; " >< a href = " javascript:selectProduct('101'); "  title = " 里程碑 " > 里程碑 </ a ></ td >
        
</ tr >
        
< tr >
          
< td >< img src = " ../Test/SiteMap/chevron.gif "  width = " 12 "  height = " 8 "  border = " 0 " ></ td >
          
< td style = " font-size:12px; width: 53px; " >< a href = " javascript:selectProduct('102'); "  title = " 董事成员 " > 董事成员 </ a ></ td >
        
</ tr >
        
< tr >
          
< td >< img src = " ../Test/SiteMap/chevron.gif "  width = " 12 "  height = " 8 "  border = " 0 " ></ td >
          
< td style = " font-size:12px; width: 53px; " >< a href = " javascript:selectProduct('103'); "  title = " 联系我们 " > 联系我们 </ a ></ td >
        
</ tr >
        
< tr >
          
< td >< img src = " ../Test/SiteMap/chevron.gif "  width = " 12 "  height = " 8 "  border = " 0 " ></ td >
          
< td style = " font-size:12px; width: 53px; " >< a href = " javascript:selectProduct('104'); "  title = " 公司理念 " > 公司理念 </ a ></ td >
        
</ tr >
        
</ table >   & nbsp; </ td >
        
< td style = " font-size: 13px; width: 8px "  valign = " top " >
        
</ td >
        
< td >< ComponentArt:CallBack id = " CallBack1 "  CacheContent = " true "  CssClass = " CallBack "  Width = " 450 "  Height = " 250 "  runat = " server "  OnCallback = " CallBack1_Callback "   >
        
< Content >
          
< asp:PlaceHolder id = " PlaceHolder1 "  runat = " server " >
            
< table cellspacing = " 0 "  cellpadding = " 0 "  border = " 0 "  style = " color:#666666; "  width = " 100% "  height = " 100% " >
            
< tr >
              
< td colspan = " 2 "  height = " 30 "  style = " font-size:12px; "  valign = " top " >
              
< asp:Label id = " lblProductTitle "  style = " font-size:15px;font-weight:bold; "  runat = " server "   />< br >
              
< asp:Label id = " lblProductTagLine "  runat = " server "   />
              
</ td >
            
</ tr >
            
< tr >
              
< td  >< asp:Image id = " imgProductImage "   runat = " server "   /></ td >
              
< td >
                           
              
</ td >
            
</ tr >
            
< tr >
              
< td colspan = " 2 "  style = " font-size:12px; " >
                
< asp:Label id = " lblProductInfo "  runat = " server "   />
              
</ td >
            
</ tr >
            
</ table >         
        
</ asp:PlaceHolder >
        
</ Content >
        
< LoadingPanelClientTemplate >
          
< table width = " 428 "  height = " 228 "  cellspacing = " 0 "  cellpadding = " 0 "  border = " 0 " >
          
< tr >
            
< td align = " center " >
            
< table cellspacing = " 0 "  cellpadding = " 0 "  border = " 0 " >
            
< tr >
              
< td style = " font-size:12px; " > 数据加载中 & nbsp; </ td >
              
< td >< img src = " ../Test/SiteMap/spinner.gif "  width = " 16 "  height = " 16 "  border = " 0 " ></ td >
            
</ tr >
            
</ table >       
            
</ td >
          
</ tr >
          
</ table >
        
</ LoadingPanelClientTemplate >
      
</ ComponentArt:CallBack >    </ td >
     
</ tr >
   
</ table >

你可能感兴趣的:(读取xml)