home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / QuickStart / util / srcview.aspx < prev    next >
Encoding:
Text File  |  2000-04-19  |  3.9 KB  |  115 lines

  1.  
  2. <%@ Register TagPrefix="Acme" TagName="SourceCtrl" Src="/quickstart/util/SrcCtrl.aspx"%>
  3. <%@ Import Namespace="System.Text" %>
  4. <%@ Import Namespace="System.IO" %>
  5.  
  6.     <link rel="stylesheet" href="/quickstart/util/style.css">
  7.  
  8.     <script language="C#" runat="server">
  9.  
  10.       public bool showtitle = true;
  11.       public bool listonly = false;
  12.       public String width = "100%";
  13.       public String path;
  14.  
  15.       public void Page_Load (Object sender, EventArgs e)
  16.       {
  17.               if (path == null)
  18.                   path = Request.QueryString["path"];
  19.  
  20.               if (path == null) 
  21.               {
  22.                   ErrorMessage.InnerHtml = "Please specify a path variable in the querystring.";
  23.                   return;
  24.               }
  25.  
  26.               String file = Request.QueryString["file"];
  27.  
  28.               if (file != null) {
  29.                   String dir = File.GetDirectoryNameFromPath(path);
  30.                   MySourceCtrl.filename = Server.MapPath(dir + "\\" + file);
  31.               }
  32.  
  33.            // BUGBUG: HtmlTable doesn't store ViewState, so must populate on every request
  34.  
  35.               FileStream fs = new FileStream(Server.MapPath(path),FileMode.Open,FileAccess.Read);
  36.               StreamReader sr = new StreamReader(fs);
  37.               String line = sr.ReadLine();
  38.  
  39.               while (line != null) 
  40.               {
  41.                   HtmlTableRow row = new HtmlTableRow();
  42.  
  43.                // BUGBUG: HtmlTableCell String Constructor is Failing...
  44.                   HtmlTableCell cell = new HtmlTableCell();
  45.  
  46.                   String[] list = line.Split(new char[] { ':' });
  47.  
  48.                   if (!(list.Length > 1)) break;
  49.  
  50.                   String sourcegroup = list[0];
  51.  
  52.                   cell.InnerHtml = "<b>" + sourcegroup + ": </b>";
  53.                   cell.Style.Add("padding-right","10");
  54.                   row.Cells.Add(cell);
  55.  
  56.                   String[] sourcelist = list[1].Split(new char[] { ',' });
  57.  
  58.                   if ((file==null)&&(sourcelist.Length>0)) 
  59.                   {
  60.                     String dir = File.GetDirectoryNameFromPath(path);
  61.                     MySourceCtrl.filename = Server.MapPath(dir + "\\" + sourcelist[0]);
  62.                     file = sourcelist[0];
  63.                   }
  64.  
  65.                   StringBuilder sb = new StringBuilder();
  66.                   for (int i=0; i<sourcelist.Length; i++) 
  67.                   {
  68.                       String sourcefile = sourcelist[i];
  69.  
  70.                       if (listonly)
  71.                           sb.Append("<a target='_blank' href='/quickstart/util/srcctrlwin.aspx?path=" + path + "&file=" + sourcefile + "'>");
  72.                       else
  73.                           sb.Append("<a href='/quickstart/util/srcview.aspx?path=" + path + "&file=" + sourcefile + "'>");
  74.  
  75.                       sb.Append(sourcefile);
  76.                       sb.Append("</a>   ");
  77.                   }
  78.  
  79.                   cell = new HtmlTableCell();
  80.                   cell.InnerHtml = sb.ToString();
  81.                   row.Cells.Add(cell);
  82.                   SourceTable.Rows.Add(row);
  83.  
  84.                   line = sr.ReadLine();
  85.               }
  86.  
  87.               fs.Close();
  88.  
  89.               if (showtitle != false) 
  90.                   Title.InnerHtml = file; //Path.GetName(path); 
  91.               else 
  92.                   Title.InnerHtml = "";
  93.       }
  94.  
  95.       public void LinkButton_Click (Object sender, EventArgs e)
  96.       {
  97.           // do nothing
  98.       }
  99.  
  100.     </script>
  101.  
  102.     <form runat="server">
  103.  
  104.         <div class="SampleHeader" style="width:<%=width%>">
  105.             <div class="SampleTitle">
  106.                 <span id="Title" runat="server">ASP+ Source Code Viewer</span>
  107.             </div>
  108.             <table id="SourceTable" MaintainState="true" style="font: 8pt Verdana" runat="server"/>
  109.         </div>
  110.  
  111.         <Acme:SourceCtrl id="MySourceCtrl" runat="server" />
  112.         <span style="color:red" id="ErrorMessage" runat="server"/>
  113.  
  114.     </form>
  115.