Asp.net百例学习笔记(1)

该博客主要介绍了ASP.NET中关于文件和目录的操作。包括使用Directory类的静态方法显示驱动器列表,获取目录和文件列表,预览文本文件前255个字符,以及将目录列表转换为HTML格式字符串用于在HTML中显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.驱动器列表显示:  //调用Directory的静态方法GetLogicalDrives
String[] myDirve=Directory.GetLogicalDrives;

2.目录和文件列表显示: 
Directory myDir=new Directory();
Directory[] subDir=myDir.GetDirectories();
File[] thisFile=myDir.GetFiles();

3./// <summary>
  /// 用于预览一个文本文件的前255个字符
  /// </summary>
  public static string PreviewFile(string funPath)
  {
   StreamReader myRd=File.OpenText(funPath);
   char[] charBuffer=new char[255];
   int iRead=myRd.ReadBlock(charBuffer,0,255);
   return (new string(charBuffer,0,iRead));
  }

4./// <summary>
  /// 返回目录列表的Html格式字符串,用于在Htlm中显示目录列表
  /// </summary>
  public static string GetSubDirList(string strPath,int iLevel)
  {
   string strDirList_out="<pre>";
   string[] strDirs=Directory.GetDirectories(strPath);
   for(int i=0;i<strDirs.Length;i++)
   {
    strDirList_out+=new string(' ',iLevel*2);
    strDirList_out+=" |__";
    strDirList_out+=strDirs[i]+"/r/n";
    strDirList_out+=GetSubDirList(strDirs[i],iLevel+1);
   }
   strDirList_out+="</pre>";
   return strDirList_out;
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值