singlefile.aspx

来自「本书通过100个精彩实例」· ASPX 代码 · 共 49 行

ASPX
49
字号
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Xsl" %>

<Script Language="C#" runat="server">
public void Page_Load(Object sender, EventArgs e) {
  XmlDocument dom;
  XslTransform xsl = new XslTransform();

  // Do we have the Wrox Pro ASP.NET book in the Cache?
  if (Cache["1861004885.xml"] == null) {
    CacheStatus.Text = "Item not present, updating the Cache...";
    UpdateCache("1861004885.xml");
  }
  else
    CacheStatus.Text = "Retrieving from Cache";

  // Load the transform
  xsl.Load(Server.MapPath("book.xsl"));

  dom = (XmlDocument)Cache["1861004885.xml"];

  BookDisplay.Document = dom;
  BookDisplay.Transform = xsl;

}

public void UpdateCache(string strItem)
{
    string strPath;
    XmlDocument dom = new XmlDocument();

    // Determine the file path the the file to monitor
    strPath = Server.MapPath(strItem);

    // Load the file into an Xml Dom
    dom.Load(strPath);

    // Create a CacheDependency on the file
    CacheDependency dependency = new CacheDependency(strPath);

    // Cache the XML document
    Cache.Insert(strItem, dom, dependency);

}
</Script>
Status: <asp:label id="CacheStatus" runat=server/>
<br>
<asp:xml id="BookDisplay" runat=server/>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?