home *** CD-ROM | disk | FTP | other *** search
- <%
- /*=====================================================================
- File: FileBrowser.aspx
-
- Summary:
-
- ---------------------------------------------------------------------
- This file is part of the Microsoft NGWS SDK Code Samples.
-
- Copyright (C) 2000 Microsoft Corporation. All rights reserved.
-
- This source code is intended only as a supplement to Microsoft
- Development Tools and/or on-line documentation. See these other
- materials for detailed information regarding Microsoft code samples.
-
- THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
- KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
- PARTICULAR PURPOSE.
- =====================================================================*/
-
- %>
-
- <%@ Page Language="C#" %>
- <%@ Import Namespace="System" %>
- <%@ Import Namespace="System.Reflection" %>
- <%@ Import Namespace="System.Collections" %>
- <%@ Import Namespace="System.IO" %>
- <%@ Import Namespace="System.Threading" %>
- <%@ Import Namespace="System.Text" %>
- <%@ Import Namespace="LangUtil" %>
-
-
- <%
- %>
- <Script runat=server>
- private Directory CurrentDir = null;
-
-
- public class FileComparer : IComparer{
- public int Compare( Object First, Object Second ) {
- return (
- String.Compare(
- ((File)First).Name,
- ((File)Second).Name,
- true
- )
- );
- }
- }
-
- public class DirectoryComparer : IComparer{
- public int Compare( Object First, Object Second ) {
- return (
- String.Compare(
- ((Directory)First).Name,
- ((Directory)Second).Name,
- true
- )
- );
- }
- }
-
-
- // Does what it says. Calling this method means that caller is still navigating and
- // hasn't chosen a file yet.
-
- public void ListDirectoryContents(TextWriter HTMLOutput, Directory Dir){
- Response.Write("<Span style=\"font-weight:bold\">Current directory:</span> " + Dir.FullName + "<BR>");
- Response.Flush();
- // list Drives
- string[] Drives = Directory.GetLogicalDrives();
- Array.Sort(Drives);
- for (int i = 0; i < Drives.Length; ++i){
- HTMLOutput.Write("<IMG SRC=\"t.gif\" class=\"Icons\">");
- HTMLOutput.WriteLine(
- "<A HREF=\"FileBrowser.aspx?NewDrive="
- + Drives[i]
- + "&CurrentDir="
- + CurrentDir.FullName
- + "\">"
- + Drives[i]
- + "</A>");
- HTMLOutput.WriteLine("<BR>");
- }
-
- // list parent of current drive.
- if (CurrentDir.Parent != null){
- HTMLOutput.Write(
- "<IMG SRC=\"tplus.gif\" class=\"Icons\"><IMG SRC=\"foldericon.gif\" class=\"Icons\">"
- );
- HTMLOutput.Write(
- "<A class=\"Directory\" HREF=\"FileBrowser.aspx?RequestDirectory="
- + CurrentDir.Parent.FullName
- + "&CurrentDir="
- + CurrentDir.FullName
- + "&GetParent="
- + "\"><parent directory></A><BR>"
- );
- }
- Directory[] Dirs = Directory.GetDirectoriesInDirectory(CurrentDir.FullName);
- DirectoryComparer DirComp = new DirectoryComparer();
- Array.Sort(Dirs, DirComp);
- for (int i = 0; i < Dirs.Length; ++i){
- HTMLOutput.Write(
- "<IMG SRC=\"tplus.gif\" class=\"Icons\"><IMG SRC=\"foldericon.gif\" class=\"Icons\"> "
- );
- HTMLOutput.WriteLine(
- "<A HREF=\"FileBrowser.aspx?RequestDirectory="
- + Dirs[i].FullName
- + "&CurrentDir="
- + CurrentDir.FullName
- + "\" class=\"Directory\">"
- + Dirs[i].Name
- + "</A>");
- HTMLOutput.WriteLine("<BR>");
- }
-
- File[] Files = Dir.GetFiles("*");
- FileComparer FileComp = new FileComparer();
- Array.Sort(Files, FileComp);
- for (int i = 0; i < Files.Length; ++i){
- HTMLOutput.Write("<IMG SRC=\"t.gif\" class=\"Icons\">");
- HTMLOutput.WriteLine(
- "<A class=\"File\" target=\"menu\" HREF=\"Toc.aspx?Add="
- + Files[i].Name
- + "&CurrentDir="
- + CurrentDir.FullName
- + "\""
- + "onclick=\"javascript:window.close();\">"
- + Files[i].Name
- + "</A>");
- HTMLOutput.WriteLine("<BR>");
- }
- }
-
-
-
- /***************************************************/
-
- // Use Load as the main for the Web request.
-
-
-
- void Page_Load(Object sender, EventArgs EvArgs){
- Response.Write("<HTML><HEAD><style type=\"text/css\">@import url(AddFile.css);</style><Title>ClassView: Microsoft NGWS SDK Sample</Title></HEAD><Body>");
- try{
- // load any possible values;
- NameValueCollection QueryStrings = Request.QueryString;
- string[] Keys, Values;
-
- if (QueryStrings.Count > 0)
- Response.Write("Writing all parameters passed to this page.<BR>");
- for (int j = 0; j < QueryStrings.Count; ++j){
- Response.Write("Key: \"" + QueryStrings.AllKeys[j] + "\" Value: \"" + QueryStrings.All[j] + "\"<BR>");
- }
-
- // if no one has chosen a directory to add yet, start with SysDir.
- if (QueryStrings.Count == 0){
- // set initial directory
- CurrentDir = new Directory(Environment.SystemDirectory);
- ListDirectoryContents(Response.Output, CurrentDir);
- }
-
- // if a new drive has been chosen, build a new directory and list that.
- else if (QueryStrings["NewDrive"] != null){
- try{
- Directory TempDirectory = new Directory(QueryStrings["NewDrive"]);
- CurrentDir = TempDirectory;
- }
- catch(Exception Ex){
- if (Ex is DirectoryNotFoundException){
- Response.Write("The " + QueryStrings["NewDrive"] + " drive isn't currently available. Try again.<BR>");
- }
- CurrentDir = new Directory(QueryStrings["CurrentDir"]);
- }
- ListDirectoryContents(Response.Output, CurrentDir);
- }
-
- // if a directory has been chosen, build a new directory and list that.
- else if (
- QueryStrings["RequestDirectory"] != null
- && QueryStrings["CurrentDir"] != null
- && QueryStrings["RequestFile"] == null
- && QueryStrings["NewDrive"] == null
- ){
- CurrentDir = new Directory(QueryStrings["RequestDirectory"]);
- ListDirectoryContents(Response.Output, CurrentDir);
-
- }
-
- // otherwise, we are going to try to load an assembly.
- else {
- CurrentDir = new Directory(QueryStrings["CurrentDir"]);
- Response.Write(
- "Yes, we are supposed to load \""
- + CurrentDir.FullName
- + "\\"
- + QueryStrings["RequestFile"]
- + "\".<BR>"
- );
- ListDirectoryContents(Response.Output, CurrentDir);
- }
- }
- catch(Exception Ex){
-
- Response.Write(Ex.GetType().Name
- + " caught at : "
- + Ex.TargetSite.ReflectedType.Name
- + "."
- + Ex.TargetSite.Name
- + " >>" + Ex.Message);
- Exception inner = Ex.InnerException;
- while (inner != null){
- Response.Write("<BR>InnerException is : "
- + inner.GetType().Name
- + " --> "
- + inner.Message);
- inner = inner.InnerException;
- }
- }
- } //END OF Load
-
- </Script>
-
- </Body>
- </HTML>
-
-