| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 689 人关注过本帖
标题:[求助]文件路径问题
只看楼主 加入收藏
marer
Rank: 2
等 级:新手上路
威 望:3
帖 子:928
专家分:0
注 册:2005-7-18
收藏
 问题点数:0 回复次数:4 
[求助]文件路径问题

近日在做一个有关读取文件路径的东东,但路径中的中文文件夹名不可以超过四个字,不然会报错,请版主帮忙看一下:
例如路径为:e:\abc\abc\新建文件夹,就会报错,但是e:\abc\abc\abcccccccccccc,再长也不报错。

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Configuration;
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 RS
{
/// <summary>
/// CommunityManager 的摘要说明。
/// </summary>
public class CommunityManager : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlTable Table1;
private string path="";

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
if(Request.QueryString["path"]==null)
{
this.Table1.Rows[1].Cells[0].InnerHtml="<p align=center><a href=CommunityManager.aspx?path="+ConfigurationSettings.AppSettings["interspace"].ToString()+"\\public class='navLink'><font color='#003366'>公共空间</font></a></p>";
this.Table1.Rows[2].Cells[0].InnerHtml="<p align=center><a href=CommunityManager.aspx?path="+ConfigurationSettings.AppSettings["interspace"].ToString()+"\\private class='navLink'><font color='#003366'>个人空间</font></a></p>";
this.Table1.Rows[1].Cells[1].InnerHtml="<p align=center><a href=addProto.aspx?path="+ConfigurationSettings.AppSettings["interspace"].ToString()+"\\public class='navLink'><font color='#003366'>添加文件夹</font></a>";
this.Table1.Rows[2].Cells[1].InnerHtml="<p align=center><a href=addProto.aspx?path="+ConfigurationSettings.AppSettings["interspace"].ToString()+"\\private class='navLink'><font color='#003366'>添加文件夹</font></a>";
string[] dir=Directory.GetDirectories(ConfigurationSettings.AppSettings["interspace"].ToString()+"\\public");
this.Table1.Rows[1].Cells[2].InnerHtml="<p align=center><font color='#003366' class='fon'>"+dir.Length+"文件夹</font></p>";
string[] files=Directory.GetFiles(ConfigurationSettings.AppSettings["interspace"].ToString()+"\\public");
this.Table1.Rows[1].Cells[3].InnerHtml="<p align=center><font color='#003366' class='fon'>"+files.Length+"文件</font></p>";
dir=Directory.GetDirectories(ConfigurationSettings.AppSettings["interspace"].ToString()+"\\private");
this.Table1.Rows[2].Cells[2].InnerHtml="<p align=center><font color='#003366' class='fon'>"+dir.Length+"文件夹</font></p>";
files=Directory.GetFiles(ConfigurationSettings.AppSettings["interspace"].ToString()+"\\private");
this.Table1.Rows[2].Cells[3].InnerHtml="<p align=center><font color='#003366' class='fon'>"+files.Length+"文件</font></p>";
}
else
{
path=Request.QueryString["path"].ToString();
DirectoryInfo di=new DirectoryInfo(path);
DirectoryInfo[] dir=di.GetDirectories();
FileInfo[] files=di.GetFiles();
if(dir.Length+files.Length>this.Table1.Rows.Count-1)
{
for(int i=0;i<dir.Length;i++)
{
HtmlTableRow r=new HtmlTableRow();
r.BgColor="#ffffff";
for(int j=0;j<4;j++)
{
HtmlTableCell cell=new HtmlTableCell();
cell.Align="center";
r.Cells.Add(cell);
}
this.Table1.Rows.Add(r);
}
for(int i=0;i<files.Length;i++)
{
HtmlTableRow rr=new HtmlTableRow();
rr.BgColor="#ffffff";
for(int j=0;j<4;j++)
{
HtmlTableCell cells=new HtmlTableCell();
cells.Align="center";
rr.Cells.Add(cells);
}
this.Table1.Rows.Add(rr);
}
}
int rowcount=1;
for(int i=0;i<dir.Length;i++)
{
this.Table1.Rows[rowcount].Cells[0].InnerHtml="<p align=center><a href=CommunityManager.aspx?path="+dir[i].FullName+" class='navLink'><font color='#003366'>"+dir[i].Name+"</font></a></p>";
this.Table1.Rows[rowcount].Cells[1].InnerHtml="<p align=center><a href=addProto.aspx?path="+dir[i].FullName+" class='navLink'><font color='#003366'>添加文件夹</font></a></p>";
string[] childdir=Directory.GetDirectories(dir[i].FullName);
this.Table1.Rows[rowcount].Cells[2].InnerHtml="<p align=center><font color='#003366' class='fon'>"+childdir.Length+"文件夹</font></p>";
string[] childfile=Directory.GetFiles(dir[i].FullName);
this.Table1.Rows[rowcount].Cells[3].InnerHtml="<p align=center><font color='#003366' class='fon'>"+childfile.Length+"文件</font></p>";
rowcount++;
}
for(int i=0;i<files.Length;i++)
{
this.Table1.Rows[rowcount].Cells[0].InnerHtml="<p align=center><font color='#003366' class='fon'>"+files[i].Name+"</font></p>";
this.Table1.Rows[rowcount].Cells[1].InnerHtml="<p>&nbsp;</p>";
this.Table1.Rows[rowcount].Cells[2].InnerHtml="<p>&nbsp;</p>";
this.Table1.Rows[rowcount].Cells[3].InnerHtml="<p>&nbsp;</p>";
rowcount++;
}
}
}
}
#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
}
}

搜索更多相关主题的帖子: using 文件路径 System abc Web 
2006-06-21 17:34
marer
Rank: 2
等 级:新手上路
威 望:3
帖 子:928
专家分:0
注 册:2005-7-18
收藏
得分:0 
怎么没人回答啊?斑主呢?在哪里?救命!!!

public class 人生历程 extends Thread{public void run(){while(true){努力,努力,再努力!!;Thread.sleep(0);}}}
2006-06-22 13:48
marer
Rank: 2
等 级:新手上路
威 望:3
帖 子:928
专家分:0
注 册:2005-7-18
收藏
得分:0 
好在自己解决了,不知版主们是不愿回答还是不会?

public class 人生历程 extends Thread{public void run(){while(true){努力,努力,再努力!!;Thread.sleep(0);}}}
2006-06-27 16:02
noshow
Rank: 2
等 级:新手上路
威 望:4
帖 子:1127
专家分:0
注 册:2006-4-21
收藏
得分:0 

我看不是斑竹不帮你解决 是你的代码这么多 看起来头大袄


此号自封于2006年11月30日
2006-06-27 16:08
marer
Rank: 2
等 级:新手上路
威 望:3
帖 子:928
专家分:0
注 册:2005-7-18
收藏
得分:0 
实际看不看代码的吧,我把代码贴上来只是为了进行参考,代码执行没有问题,肯定不是代码的问题,只是设置上的问题,所谓难者不会,会者不难。

public class 人生历程 extends Thread{public void run(){while(true){努力,努力,再努力!!;Thread.sleep(0);}}}
2006-06-28 15:51
快速回复:[求助]文件路径问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015340 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved