您的位置:首页 > 移动开发 > Objective-C

目录文件操作实例[1]_列出本地硬盘上的所有驱动器

2007-11-27 18:23 405 查看
在此实例中需要先将System.IO空间引入,然后在VS编辑器中输入以下代码,且以ListDrivers.aspx保存。 


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;


using System.IO;




namespace PracticeProject.Practice1




...{




    /**//// <summary>


    /// ListDrives 的摘要说明。


    /// </summary>


    public class ListDrivers : System.Web.UI.Page




    ...{


        private void Page_Load(object sender, System.EventArgs e)




        ...{


            if (!IsPostBack)




            ...{


                BindDrivers();


      
4000
      }


        }




        private void BindDrivers()




        ...{


            string[] achDrivers = Directory.GetLogicalDrives();


            int nNumOfDrivers = achDrivers.Length;


            Response.Write("<ul>");


            for (int i = 0;i < nNumOfDrivers; i++)




            ...{


                Response.Write("<li><a href='ListDir.aspx?dir=");


                Response.Write(Server.UrlEncode(achDrivers[i]));


                Response.Write("' target='_blank'>" + achDrivers[i]);


                Response.Write("</a><br>");


            }


            Response.Write("</ul>");


        }






        Web 窗体设计器生成的代码#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


    }


}






<%...@ Page language="c#" Codebehind="ListDrivers.aspx.cs" AutoEventWireup="false" Inherits="PracticeProject.Practice1.ListDrivers" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >


<html>


    <head>


        <title>ListDrives</title>


        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">


        <meta name="CODE_LANGUAGE" Content="C#">


        <meta name="vs_defaultClientScript" content="JavaScript">


        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">


    </head>


    <body MS_POSITIONING="GridLayout">


        <form id="Form1" method="post" runat="server">


        </form>


    </body>


</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息