
本網(wǎng)戰使用了一些圖片,請在相冊中查找
站點(diǎn)主頁(yè) index.htm 內容
<html> <head> <TITLE>基于Web的文件查看器</TITLE> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <frameset cols="237,767" rows="*"> <frame src="treeview.aspx"> <frame name="frameview" src="說(shuō)明.txt"> </frameset> <noframes> <body bgcolor="#FFFFFF" text="#000000"> </body> </noframes> </html>文件 說(shuō)明.txt 內容
基于Web 的文件瀏覽查看器
本系統為一個(gè)ASP.NET應用程序,使用C#語(yǔ)言開(kāi)發(fā)
本系統在一個(gè)瀏覽器/服務(wù)器模式下模仿Windows資源管理器的文件系統樹(shù)狀列表
并提供一定類(lèi)型的文件的查看功能
本系統不是數據庫應用系統,因此不需要配置任何數據庫
將所有的文件拷貝到一個(gè)Web服務(wù)器上的某個(gè)虛擬目錄即可運行
但服務(wù)器必須安裝 IIS 及 Microsoft .NET Framwork 1.1簡(jiǎn)體中文版
本系統默認根目錄為 D:\ ,但可以在系統運行時(shí)修改根目錄,也可進(jìn)入fileview.aspx.cs
中第19行修改默認根目錄然后重新編譯即可
本系統主頁(yè)面為 index.htm
本系統為一個(gè)ASP.NET應用,因此該程序運行在 ASPNET 用戶(hù)賬號下,該賬號權限一般比較低
因此若本系統不能查看某個(gè)文件目錄,此時(shí)需要進(jìn)入相關(guān)的系統管理工具設置ASPNET的權限
客戶(hù)端建議安裝 IE6.0及其以上版本
************** 版權聲明 *****************************************************
你可以任意參考修改和引用所有的代碼,可將所有的代碼
不受限制的使用于任意性質(zhì)的系統中.
但在使用時(shí)請尊重知識產(chǎn)權,修改的時(shí)候望手下留情,
請不要竄改或刪除可憐巴巴這么一點(diǎn)的知識產(chǎn)權聲明
以尊重漫漫長(cháng)夜辛苦敲鍵盤(pán)的人們的勞動(dòng)成果
南京 袁永福 2004-8-8
yyf9989@hotmail.com
*************** 文件列表 ****************************************************
bmp.bmp gif.bmp htm.bmp html.bmp
jpeg.bmp jpg.bmp txt.bmp new.bmp
用于在樹(shù)狀列表中表示文件類(lèi)型的圖標BMP文件,其中文件名就是
適于該圖標的文件的擴展名,默認為 new.bmp
你可以自己添加相應的文件類(lèi)型的BMP, 所有的這些BMP大小都是 16*16象素
child.gif close.bmp collapse.gif expend.gif
open.bmp line.gif lastchild.gif
用于在樹(shù)狀列表中表現樹(shù)狀結構的圖片
index.htm 系統主頁(yè)面,為一個(gè)分為左右兩個(gè)框架的靜態(tài)HTML頁(yè)面
fileview.aspx 用于獲得文件列表信息及文件信息和內容的ASP.NET頁(yè)面
treeview.aspx 用于維護樹(shù)狀列表的ASP.NET頁(yè)面
htmlcontent.xml 為一個(gè)XSLT文檔,用于根據文件信息來(lái)生成顯示該文件內容的HTML代碼
文件 treeview.aspx 內容
<%@ Page language="c#" AutoEventWireup="false" Inherits="fileview.treeview" %>
<!-----------------------------------------------------------------------------
基于Web的文件查看器之文件樹(shù)狀列表
本頁(yè)面綜合使用了 ASP.NET , XML ,XSLT 和 DHTML技術(shù)
本頁(yè)面用于維護一個(gè)文件樹(shù)狀列表,該樹(shù)狀列表模仿了Windows資源管理器的文件樹(shù)狀列表
你可以任意參考修改和引用所有的代碼,可將所有的代碼不受限制的使用于任意性質(zhì)的系統中.
但在使用時(shí)請尊重知識產(chǎn)權,修改的時(shí)候望手下留情,
請不要竄改或刪除可憐巴巴這么一點(diǎn)的知識產(chǎn)權聲明
南京 袁永福 2004-8-8
yyf9989@hotmail.com
------------------------------------------------------------------------------>
<%
string strPath = this.Request.Form["baseurl"] ;
if(strPath == null || strPath.Trim().Length == 0 )
strPath = fileview.FileView.BasePath ; // 顯示當前根目錄
strPath = strPath.Trim();
if(strPath.EndsWith("\\")==false)
strPath = strPath + "\\";
if(System.IO.Directory.Exists(strPath))
fileview.FileView.BasePath = strPath ;
%>
<HTML>
<HEAD>
<title>動(dòng)態(tài)的XML樹(shù)狀列表</title>
<style>
body{ font-family: "宋體"; font-size: 12px}
.TreeNode { FONT-SIZE: 12px; CURSOR: hand }
.FocusNode { BORDER-RIGHT: #ff0000 1px solid;
BORDER-TOP: #ff0000 1px solid; FONT-SIZE: 12px; MARGIN-BOTTOM: -2px;
BORDER-LEFT: #ff0000 1px solid; CURSOR: hand; COLOR: #ffffff;
BORDER-BOTTOM: #ff0000 1px solid; BACKGROUND-COLOR: #000099; TEXT-ALIGN: left }
</style>
</HEAD>
<body leftmargin="1" topmargin="1">
<form id="Form1" method="post">
<div>
<span id="maintree" childlist="fileview.aspx?type=list">根節點(diǎn)
<input type="text" name="baseurl" style="width:72" value="<%= strPath%>" />
<input type="submit" value="刷新" /></span>
</div>
</form>
<!--
XML數據島,在此定義用于進(jìn)行匹配的XSLT文檔,
該XSLT文檔用于支持動(dòng)態(tài)的生成樹(shù)狀列表
-->
<xml id="treexsl">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" />
<xsl:template match="/*">
<xsl:variable name="baseurl">
<xsl:value-of select="@baseurl" />
</xsl:variable>
<table border="0" width="100%" cellspacing="0" cellpadding="0" id="createdtable">
<xsl:for-each select="*">
<!-- 樹(shù)狀列表是按照節點(diǎn)文本進(jìn)行排序的 -->
<xsl:sort select="concat(@file , @text)" />
<!-- 計算當前節點(diǎn)的代號 -->
<xsl:variable name="nodeid">
<xsl:choose>
<xsl:when test="@id!=‘‘">
<xsl:value-of select="concat(‘ID‘ , @id)" />
</xsl:when>
<xsl:when test="boolean(‘true‘)">
<xsl:value-of select="translate(name(),‘.‘,‘_‘)" />
</xsl:when>
</xsl:choose>
</xsl:variable>
<tr>
<td valign="top" align="left" width="16">
<xsl:choose>
<xsl:when test="@childlist != ‘‘">
<xsl:if test="position()!=last()">
<xsl:attribute name="background">line.gif</xsl:attribute>
</xsl:if>
<img src="collapse.gif" expend="0">
<xsl:attribute name="id">
<xsl:value-of select="concat($nodeid,‘expend‘)" />
</xsl:attribute>
<xsl:attribute name="onclick">ExpendNodeByID(‘<xsl:value-of select="$nodeid" />‘);</xsl:attribute>
</img>
</xsl:when>
<xsl:when test="boolean(‘true‘)">
<xsl:if test="position()!=last()">
<img src="child.gif" />
</xsl:if>
<xsl:if test="position()=last()">
<img src="lastchild.gif" />
</xsl:if>
</xsl:when>
</xsl:choose>
</td>
<td valign="top" nowrap="1">
<!--
用于生成樹(shù)狀列表的圖標HTML代碼
-->
<img align="absmiddle" onclick="ExpendNode(this.nextSibling)" width="16" height="16">
<xsl:attribute name="id">
<xsl:value-of select="concat($nodeid,‘icon‘)" />
</xsl:attribute>
<xsl:attribute name="src">
<xsl:choose>
<xsl:when test="@img!=‘‘">
<xsl:value-of select="@img" />
</xsl:when>
<xsl:when test="@childlist != ‘‘">close.bmp</xsl:when>
<xsl:when test="boolean(‘true‘)">default.bmp</xsl:when>
</xsl:choose>
</xsl:attribute>
</img>
<!-- 生成樹(shù)狀列表節點(diǎn)的文本 -->
<a class="TreeNode" valign="top" onclick="ExpendNode(this)" target="frameview">
<xsl:attribute name="id">
<xsl:value-of select="$nodeid" />
</xsl:attribute>
<xsl:if test="@href != ‘‘">
<xsl:attribute name="href">
<xsl:value-of select="concat($baseurl , @href)" />
</xsl:attribute>
</xsl:if>
<xsl:if test="@childlist!=‘‘">
<xsl:attribute name="childlist">
<xsl:value-of select="@childlist" />
</xsl:attribute>
<xsl:attribute name="href">
<xsl:value-of select="concat($baseurl , @childlist)" />
</xsl:attribute>
</xsl:if>
<xsl:value-of select="concat( ‘ ‘ ,@text)" />
</a>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
</xml>
<script language="javascript">
<!--
var CurrentTreeNode ; // 定義樹(shù)狀列表的當前節點(diǎn)對象
var intIDCount = 1234; // 定義一個(gè)ID號初始值
var CurrentLoadingID = "";
// 初始化XSLT模板
var xslDoc = new ActiveXObject("MSXML.DOMDocument");
xslDoc.async = false;
xslDoc.load (treexsl.XMLDocument);
var resultDoc = new ActiveXObject("MSXML.DOMDocument");
resultDoc.onreadystatechange = XMLStateChange ;
resultDoc.async = true;
function XMLStateChange()
{
//window.status = resultDoc.readyState ;
if(resultDoc.readyState == 4 )
{
var objLabel = document.getElementById("loadflag" + intIDCount) ;
if(resultDoc.parseError.errorCode != 0)
objLabel.innerText = "加載錯誤:" + resultDoc.parseError.reason ;
else
{
var myObj = document.getElementById(CurrentLoadingID + "expend");// 獲得節點(diǎn)的展開(kāi)點(diǎn)圖片對象
var myIcon = document.getElementById(CurrentLoadingID + "icon"); // 獲得節點(diǎn)的圖標圖片對象
var MainObj = document.getElementById(CurrentLoadingID); // 獲得節點(diǎn)的文本對象
var myTable ;
var strHTML = resultDoc.transformNode(xslDoc) ;
window.status = "加載完畢,正在生成子節點(diǎn)列表..." ;
MainObj.insertAdjacentHTML("afterEnd", strHTML );
MainObj.removeAttribute("childlist");
// 獲得剛剛加載的子節點(diǎn)表格對象并進(jìn)行初始化
myTable = document.getElementById("createdtable");
objLabel.style.display="none";
if(myTable != null)
{
myTable.style.display = "";
myTable.id = CurrentLoadingID + "table";
}
intIDCount ++ ;
//myTable.style.display="none";
if(myObj != null)
{
myTable.style.display="";
myObj.expend = "1";
myObj.src = "expend.gif";
myIcon.src = "open.bmp";
myIcon.align = "absmiddle";
}
window.status = "";
}
}
}
// 展開(kāi)一個(gè)樹(shù)狀列表節點(diǎn)并設置為當前節點(diǎn)
function ExpendNode(obj)
{
if( CurrentTreeNode != obj && CurrentTreeNode != null)
{
CurrentTreeNode.className = "TreeNode";
}
CurrentTreeNode = obj;
CurrentTreeNode.className = "FocusNode";
window.status = obj.innerText ;
ExpendNodeByID(obj.id);
}
// 展開(kāi)指定編號的樹(shù)狀列表的節點(diǎn),若該節點(diǎn)的子節點(diǎn)未加載則加載之
function ExpendNodeByID(strID)
{
var myObj = document.getElementById(strID + "expend"); // 獲得節點(diǎn)的展開(kāi)點(diǎn)圖片對象
var myIcon = document.getElementById(strID + "icon"); // 獲得節點(diǎn)的圖標圖片對象
var MainObj = document.getElementById(strID); // 獲得節點(diǎn)的文本對象
var myTable ;
myTable = document.getElementById(strID + "table"); // 獲得子節點(diǎn)表格
if(MainObj != null && MainObj.childlist != null && myTable == null)
{
// 加載子節點(diǎn)
MainObj.insertAdjacentHTML("afterEnd",
"<div id=‘loadflag" + intIDCount + "‘> 正在加載子節點(diǎn)...</div>");
window.status = "正在加載 " + MainObj.innerText + " 的子節點(diǎn)...";
CurrentLoadingID = strID;
resultDoc.load(MainObj.childlist);
return ;
}
// 展開(kāi)或收縮子節點(diǎn)
if(MainObj != null && myObj != null && myIcon != null && myTable != null )
{
if(myObj.expend=="1")
{
myTable.style.display="none";
myObj.expend = "0";
myObj.src = "collapse.gif";
myIcon.src = "close.bmp";
myIcon.align = "absmiddle";
}
else
{
myTable.style.display="";
myObj.expend = "1";
myObj.src = "expend.gif";
myIcon.src = "open.bmp";
myIcon.align = "absmiddle";
}
window.status = "文件夾:" + MainObj.innerText + " 共有子節點(diǎn) " + myTable.rows.length + " 個(gè)";
}
}
// 頁(yè)面加載的時(shí)候加載根節點(diǎn)
ExpendNodeByID("maintree");
//document.getElementById("maintree").innerText = "根節點(diǎn)";
-->
</script>
</body>
</HTML>
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;
namespace fileview
{
/// <summary>
/// 返回文件列表,單個(gè)文件信息和文件所有內容的頁(yè)面
///
/// 你可以任意參考修改和引用所有的代碼,可將所有的代碼不受限制的使用于任意性質(zhì)的系統中.
///
/// 但在使用時(shí)請尊重知識產(chǎn)權,修改的時(shí)候望手下留情,
///
/// 請不要竄改或刪除可憐巴巴這么一點(diǎn)的知識產(chǎn)權聲明
///
/// 南京 袁永福 2004-8-8
/// yyf9989@hotmail.com
/// </summary>
public class FileView : System.Web.UI.Page
{
private static string c_BasePath = "D:\\"; // 初始化文件夾路徑
private const string c_List = "list"; // 返回文件列表的參數
private const string c_Get = "get"; // 獲得文件信息的參數
private const string c_GetFile = "getfile"; // 獲得文件內容的參數
private const string c_PreView = "preview"; // 獲得圖片的預覽結果
private static string strViewType = "list" ;
// 文檔內容的類(lèi)型列表
private static System.Collections.Specialized.NameValueCollection myContentTypeList = null;
// 保存文件和目錄的全路徑名稱(chēng)的列表
static System.Collections.ArrayList myFileList = new ArrayList();
/// <summary>
/// 設置,返回初始化根目錄
/// </summary>
public static string BasePath
{
get{ return c_BasePath;}
set
{
c_BasePath = value;
myFileList.Clear();
}
}
private void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置用戶(hù)代碼以初始化頁(yè)面
string strPath = null;
string strType = null;
// 初始化文檔類(lèi)型列表
if(myContentTypeList == null)
{
myContentTypeList = new System.Collections.Specialized.NameValueCollection();
myContentTypeList.Add("js" ,"text");
myContentTypeList.Add("jsp" ,"text");
myContentTypeList.Add("asp" ,"text");
myContentTypeList.Add("txt" ,"text");
myContentTypeList.Add("cpp" ,"text");
myContentTypeList.Add("c" ,"text");
myContentTypeList.Add("h" ,"text");
myContentTypeList.Add("frm" ,"text");
myContentTypeList.Add("sql" ,"text");
myContentTypeList.Add("cs" ,"text");
myContentTypeList.Add("vb" ,"text");
myContentTypeList.Add("cls" ,"text");
myContentTypeList.Add("java" ,"text");
myContentTypeList.Add("ini" ,"text");
myContentTypeList.Add("resx" ,"text/xml");
myContentTypeList.Add("xml" ,"text/xml");
myContentTypeList.Add("xsd" ,"text/xml");
myContentTypeList.Add("xsl" ,"text/xml");
myContentTypeList.Add("bmp" ,"image/bmp");
myContentTypeList.Add("jpg" ,"image/jpeg");
myContentTypeList.Add("jpeg" ,"image/jpeg");
myContentTypeList.Add("tiff" ,"image/tiff");
myContentTypeList.Add("png" ,"image/png");
myContentTypeList.Add("gif" ,"image/gif");
myContentTypeList.Add("ico" ,"image/x-icon");
myContentTypeList.Add("doc" ,"application/msword");
myContentTypeList.Add("xls" ,"application/x-msexcel");
myContentTypeList.Add("ppt" ,"application/x-mspowerpoint");
myContentTypeList.Add("zip" ,"application/x-zip-compressed");
}
// 分析參數,獲得對象編號和參數類(lèi)型
if(this.Request["viewtype"]!= null)
{
strViewType = this.Request["viewtype"];
return ;
}
int Index = ToInt32Value(this.Request["id"],-1);
strType = this.Request["type"];
if(c_List == strType )
{
// 獲得文件列表
if(Index < 0 || Index > myFileList.Count - 1 )
{
myFileList.Clear();
strPath = c_BasePath ;
}
else
{
strPath = (string)myFileList[Index];
}
// 生成描述文件列表的XML文檔
System.Xml.XmlDocument myDoc = new System.Xml.XmlDocument();
myDoc.LoadXml("<filelist />");
myDoc.DocumentElement.SetAttribute("text",System.IO.Path.GetFileName(strPath));
myDoc.DocumentElement.SetAttribute("viewtype",strViewType);
if( (System.IO.File.GetAttributes(strPath) & System.IO.FileAttributes.Directory) != 0 )
{
string [] strFiles = System.IO.Directory.GetFileSystemEntries( strPath , "*.*");
for(int iCount = 0 ; iCount < strFiles.Length ; iCount ++)
{
System.Xml.XmlElement myElement = myDoc.CreateElement("file");
myDoc.DocumentElement.AppendChild(myElement);
try
{
myElement.SetAttribute("text",System.IO.Path.GetFileName(strFiles[iCount]));
myElement.SetAttribute("id", myFileList.Count.ToString() );
if( (System.IO.File.GetAttributes(strFiles[iCount]) & System.IO.FileAttributes.Directory) == 0 )
{
// 本路徑為一個(gè)文件
string strFileExt = System.IO.Path.GetExtension(strFiles[iCount]);
if(strFileExt != null && strFileExt.Length > 0 )
{
strFileExt = strFileExt.Substring(1);
strFileExt = strFileExt.Trim();
// 設置文件的圖標
if(strFileExt == "ico")
myElement.SetAttribute("img", "fileview.aspx?type=getfile&id=" + myFileList.Count.ToString());
else
{
if(System.IO.File.Exists(this.MapPath(".") + "\\" + strFileExt + ".bmp"))
myElement.SetAttribute("img", strFileExt + ".bmp");
}
myElement.SetAttribute("type",strFileExt);
}
// 設置樹(shù)狀列表鏈接URL
// 若為文本文件和圖片則直接顯示,否則套用XSL格式
string strContentType = myContentTypeList.Get(strFileExt.ToLower());
if( strContentType != null
&& ( strContentType.StartsWith("image/") || strContentType.StartsWith("text")))
{
myElement.SetAttribute("href","fileview.aspx?type=getfile&id=" + myFileList.Count.ToString());
if(strContentType.StartsWith("image/"))
myElement.SetAttribute("imgfile","1");
}
else
myElement.SetAttribute("href","fileview.aspx?id=" + myFileList.Count.ToString());
myElement.SetAttribute("file","1");
myElement.SetAttribute("size",(new System.IO.FileInfo(strFiles[iCount])).Length.ToString() );
}
else
{
// 本路徑為一個(gè)目錄
myElement.SetAttribute("childlist","fileview.aspx?type=list&id=" + myFileList.Count.ToString());
myElement.SetAttribute("file","0");
}
System.DateTime dtmDate = System.IO.File.GetLastAccessTime(strFiles[iCount]);
myElement.SetAttribute("accesstime",dtmDate.ToString("yyyy-MM-dd HH:mm:ss"));
// 向對象路徑列表添加項目
myFileList.Add(strFiles[iCount]);
}
catch(Exception ext)
{
myElement.SetAttribute("text","錯誤:" + ext.Message);
break;
}
}
}
// 輸出文件列表文檔
this.Response.ContentEncoding = System.Text.Encoding.GetEncoding(936);
this.Response.Write("<?xml version=\"1.0\" encoding=\"GB2312\" ?><?xml-stylesheet type=\"text/xsl\" href=\"htmlcontent.xml\"?>");
this.Response.Write(myDoc.DocumentElement.OuterXml);
//myDoc.Save( this.Response.Output );
}
else if (c_GetFile == strType)
{ // 返回文件內容
if(Index >= 0 && Index < myFileList.Count)
{
string strFile =(string) myFileList[Index];
if( (System.IO.File.GetAttributes(strFile) & System.IO.FileAttributes.Directory) == 0 )
{
if(System.IO.File.Exists(strFile))
{
string strFileExt = GetFileExtension(strFile);
string strContentType = myContentTypeList.Get(strFileExt);
if(this.Request["preview"] != null)
{
if(strContentType.StartsWith("image/"))
{
using(System.Drawing.Image myImg = System.Drawing.Image.FromFile(strFile))
{
if( myImg.Width < 100 )
this.Response.WriteFile(strFile);
else
{
System.Drawing.Image preImg = myImg.GetThumbnailImage(100,100,null,System.IntPtr.Zero);
preImg.Save(this.Response.OutputStream , System.Drawing.Imaging.ImageFormat.Jpeg );
preImg.Dispose();
}
}
}
return ;
}
else
{
if(strContentType == null || strContentType.Length == 0 )
this.Response.WriteFile(strFile);
else
{
if(strContentType == "text")
{
this.Response.ContentEncoding = System.Text.Encoding.GetEncoding(936);
this.Response.ContentType = "text/html";
this.Response.Write("<pre>");
this.Response.WriteFile(strFile);
this.Response.Write("</pre>");
return ;
}
else
{
this.Response.ContentType = strContentType ;
this.Response.WriteFile(strFile);
}
}
}
}
}
}
}
else if ( c_PreView == strType)
{
}
else
{
// 返回文件信息
if(Index >= 0 && Index < myFileList.Count)
{
System.Xml.XmlDocument myDoc = new System.Xml.XmlDocument();
myDoc.LoadXml("<file />");
myDoc.DocumentElement.SetAttribute("type", GetFileExtension((string)myFileList[Index]));
myDoc.DocumentElement.SetAttribute("url", "fileview.aspx?type=getfile&id=" + Index.ToString());
this.Response.Write("<?xml version=\"1.0\" encoding=\"GB2312\" ?><?xml-stylesheet type=\"text/xsl\" href=\"htmlcontent.xml\"?>");
this.Response.Write(myDoc.DocumentElement.OuterXml);
}
}
}
/// <summary>
/// 根據路徑獲得文件擴展名
/// </summary>
/// <param name="strFile">文件路徑</param>
/// <returns>文件擴展名,若不存在擴展名則返回空白字符串</returns>
private string GetFileExtension(string strFile)
{
try
{
string strFileExt = System.IO.Path.GetExtension(strFile);
strFileExt = strFileExt.Substring(1).Trim().ToLower();
return strFileExt ;
}
catch
{
return "";
}
}
/// <summary>
/// 將字符串轉換為整數,若轉換失敗則返回默認值
/// </summary>
/// <param name="strData">字符串</param>
/// <param name="DefaultValue">默認值</param>
/// <returns>轉換結果</returns>
private int ToInt32Value(string strData, int DefaultValue )
{
try
{
if(strData == null)
return DefaultValue ;
else
return Convert.ToInt32(strData);
}
catch
{
return DefaultValue;
}
}
#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!--
用于根據描述單個(gè)文件信息的XML文件進(jìn)行處理,生成實(shí)際顯示該文檔的HTML頁(yè)面代碼
你可以任意參考修改和引用所有的代碼,可將所有的代碼不受限制的使用于任意性質(zhì)的系統中.
但在使用時(shí)請尊重知識產(chǎn)權,修改的時(shí)候望手下留情,
請不要竄改或刪除可憐巴巴這么一點(diǎn)的知識產(chǎn)權聲明
南京 袁永福 2004-8-8
yyf9989@hotmail.com
-->
<xsl:output method="html" />
<xsl:template match="/*">
<xsl:choose>
<xsl:when test="name(.) = ‘filelist‘ ">
<html>
<head>
<title>文件列表</title>
</head>
<body leftmargin="1" topmargin="1">
<xsl:value-of select="concat(‘文件夾‘ , @text,‘ 的子項目列表 共‘,count(*),‘個(gè)子項目‘)" />
[<a href="fileview.aspx?viewtype=list">設置列表視圖模式</a>]
[<a href="fileview.aspx?viewtype=preview">設置預覽視圖模式</a>]
<br />
<xsl:if test="@viewtype=‘preview‘">
<xsl:for-each select="*[@imgfile=‘1‘]">
<a>
<xsl:attribute name="href">
<xsl:value-of select="@href" />
</xsl:attribute>
<img>
<xsl:attribute name="src">
<xsl:value-of select="concat(@href,‘&preview=1‘)" />
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="@text" />
</xsl:attribute>
</img>
</a>
</xsl:for-each>
</xsl:if>
<xsl:if test="@viewtype=‘list‘">
<table width="100%" cellspacing="0" rules="all" bordercolor="#CC0066" border="1" id="lvwTable"
style="border-color:#CC0066;width:100%;border-collapse:collapse;Z-INDEX: 101; LEFT: 40px;font-family: 宋體; font-size: 12px">
<tr style="background-color:#CCCCFF;">
<td>文件名 </td>
<td>大小</td>
<td>類(lèi)型</td>
<td>修改時(shí)間</td>
</tr>
<xsl:for-each select="*">
<!-- 計算當前節點(diǎn)的代號 -->
<xsl:variable name="nodeid">
<xsl:choose>
<xsl:when test="@id!=‘‘">
<xsl:value-of select="concat(‘ID‘ , @id)" />
</xsl:when>
<xsl:when test="boolean(‘true‘)">
<xsl:value-of select="translate(name(),‘.‘,‘_‘)" />
</xsl:when>
</xsl:choose>
</xsl:variable>
<tr>
<td>
<img id="Img1" align="absmiddle" width="16" height="16">
<xsl:attribute name="src">
<xsl:choose>
<xsl:when test="@img!=‘‘">
<xsl:value-of select="@img" />
</xsl:when>
<xsl:when test="@childlist != ‘‘">close.bmp</xsl:when>
<xsl:when test="boolean(‘true‘)">default.bmp</xsl:when>
</xsl:choose>
</xsl:attribute>
</img>
<!-- 生成樹(shù)狀列表節點(diǎn)的文本 -->
<a class="TreeNode" valign="top">
<xsl:if test="@href != ‘‘">
<xsl:attribute name="href">
<xsl:value-of select="@href" />
</xsl:attribute>
</xsl:if>
<xsl:value-of select="concat( ‘ ‘ ,@text)" />
</a>
</td>
<td>
<xsl:value-of select="@size" />
</td>
<td>
<xsl:value-of select="@type" />
</td>
<td>
<xsl:value-of select="@accesstime" />
</td>
</tr>
</xsl:for-each>
</table>
</xsl:if>
</body>
</html>
</xsl:when>
<xsl:when test="@type=‘swf‘">
<!-- Flash 動(dòng)畫(huà),需要調用Flash播放器 -->
<html>
<head></head>
<body>
<div>
本文檔為一個(gè)Flash動(dòng)畫(huà),將使用Falsh動(dòng)畫(huà)播放器播放
<br />請確認你的計算機系統安裝了Flash動(dòng)畫(huà)播放器
</div>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0">
<param name="movie">
<xsl:attribute name="value">
<xsl:value-of select="@url" />
</xsl:attribute>
</param>
<param name="quality" value="high" />
<embed quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"
type="application/x-shockwave-flash">
<xsl:attribute name="src">
<xsl:value-of select="@url" />
</xsl:attribute>
</embed>
</object>
</body>
</html>
</xsl:when>
<!-- 圖片 -->
<xsl:when test="@type=‘jpg‘ or @type=‘jpeg‘ or @type=‘bmp‘ or @type=‘png‘ or @type=‘gif‘ or @type=‘icon‘ or @type=‘ico‘ ">
<html>
<head></head>
<body leftmargin="1" topmargin="1" bgcolor="#000000">
<div align="center">
<img border="1" align="center" style="border-color: #FF0000">
<xsl:attribute name="src">
<xsl:value-of select="@url" />
</xsl:attribute>
</img>
</div>
</body>
</html>
</xsl:when>
<!--
視頻或音頻文檔,需要調用Windows媒體播放器
以下代碼在安裝了Windows Media Player 9 的Windows2000系統上調試通過(guò)
-->
<!--xsl:when test=" @type=‘mpg‘ or @type=‘mpge‘ or @type=‘mp3‘ or @type=‘a(chǎn)vi‘ or @type=‘a(chǎn)sf‘ or @type=‘wmv‘ or @type=‘mpga‘ or @type=‘wma‘ "-->
<xsl:when test="@type!=‘‘ and contains(‘.cda.aif.aifc.aiff.asf.asx.wax.wm.wma.wmd.wmp.wmv.wmx.wpl.wvx.avi.wav.wmz.mpga.mpeg.mpg.m1v.mp2.mpa.mpemp2v.mpv2.mid.midi.rmi.au.mp3.m3u.vob‘, concat(‘.‘,@type))">
<html>
<head></head>
<body>
<div>
當前文檔為音頻或視頻文件,將使用Windows Media Player 來(lái)播放
<br />在此使用Windows Media Player 9來(lái)播放,
<br />請確保你的計算機系統上安裝了Windows Media Player 9
<br />目前支持的文件擴展名包括
<br /> .cda .aif .aifc .aiff .asf .asx .wax .wm .wma .wmd .wmp .wmv .wmx
<br /> .wpl .wvx .avi .wav .wmz .mpga .mpeg .mpg .m1v .mp2 .mpa .mpemp2v
<br /> .mpv2 .mid .midi .rmi .au .mp3 .m3u .vob
</div>
<object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" id="WindowsMediaPlayer1" width="419"
height="242">
<param name="URL">
<xsl:attribute name="value">
<xsl:value-of select="@url" />
</xsl:attribute>
</param>
</object>
</body>
</html>
</xsl:when>
<!--xsl:when test="@type=‘txt‘">
<html>
<head>
</head>
<body>
<pre id="txtpre">
<script language="vbscript">
dim txtdata
set txtdata = CreateObject("Microsoft.XMLHTTP")
txtdata.open "GET","<xsl:value-of select="@url" />" ,false
txtdata.send ""
alert txtdata.responsetext
document.getElementById("txtpre").innerHTML = txtdata.responseText
set txtdata = nothing
</script>
</pre>
</body>
</html>
</xsl:when-->
<!-- 對其他所有的文件使用javascript腳本進(jìn)行頁(yè)面重定向 -->
<xsl:when test="boolean(‘true‘)">
<script language="javascript">
document.location = "<xsl:value-of select="@url" />" ;
</script>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
聯(lián)系客服