All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
GridView中绑定日期字段格式的定义_[Asp.Net教程]
c#数据结构中对数的概念以及使用
《Effective,C#》:值类型和引用类型_.net资料_编程技术
ASP.NET2.0连接ORACLE解决方案_[Asp.Net教程]
加速PHP动态网站,MySQL索引分析和优化_php资料_编程技术
理解C#值类型与引用类型_[Asp.Net教程]
网页技巧:如何在网页上实现音乐播放?_JavaScript技术_编程技术
基于Gettext的asp.net网站多语言解决方案_[Asp.Net教程]
ASP.NET实例:多文件上传源码_[Asp.Net教程]
ASP.NET&Spring.NET&NHibernate最佳实践(四)——第3章人事子系统(1)_[Asp.Net教程]
Reading number is top 10 pictures
关于海盗的研究2
Sora aoi in China3
美女浴室写真3
原子弹轰炸长崎的珍贵照片
From China fortress sora aoi4
深圳的风光
Exquisite decoration is not paying too much3
The real super beauty15
身材野火台灣美女1
NeedWallpaper4
Download software ranking
Tram sex maniac 2 (H) rar bag10
Call Of Duty5
Call Of Duty2
ASP.NET.2.0.XML.高级编程(第3版)
Sora aoi - one of more PK
Tram sex maniac 2 (H) rar bag17
美女写真1
Such love down(擒爱记)
在线棋牌游戏3.05版
Sora aoi‘s film--Lust fan wall
delv published in(发表于) 2014/1/6 9:03:34 Edit(编辑)
Asp.net对文件夹和文件的操作类_[Asp.Net教程]

Asp.net对文件夹和文件的操作类_[Asp.Net教程]

Asp.net对文件夹和文件的操作类_[Asp.Net教程]

using System;
using System.IO;
using System.Web;


namespace SEC
{
/**////


/// 对文件和文件夹的操作类
///

public class FileControl
{
public FileControl()
{

}
/**////
/// 在根目录下创建文件夹
///

/// 要创建的文件路径
public void CreateFolder(string FolderPathName)
{
if(FolderPathName.Trim().Length>0)
{
try
{
string CreatePath = System.Web.HttpContext.Current.Server.MapPath


("../../../Images/"+FolderPathName).ToString();
if(!Directory.Exists(CreatePath))
{
Directory.CreateDirectory(CreatePath);
}
}
catch
{
throw;
}
}
}


/**////


/// 删除一个文件夹下面的字文件夹和文件
///

///
public void DeleteChildFolder(string FolderPathName)
{
if(FolderPathName.Trim().Length>0)
{
try
{
string CreatePath = System.Web.HttpContext.Current.Server.MapPath


(FolderPathName).ToString();
if(Directory.Exists(CreatePath))
{
Directory.Delete(CreatePath,true);
}
}
catch
{
throw;
}
}
}


/**////


/// 删除一个文件
///

///
public void DeleteFile(string FilePathName)
{
try
{
FileInfo DeleFile = new FileInfo(System.Web.HttpContext.Current.Server.MapPath


(FilePathName).ToString());
DeleFile.Delete();
}
catch
{
}
}
public void CreateFile(string FilePathName)
{
try
{
//创建文件夹
string[] strPath= FilePathName.Split('/');
CreateFolder(FilePathName.Replace("/" + strPath[strPath.Length-1].ToString(),"")); //创建文件



FileInfo CreateFile =new FileInfo(System.Web.HttpContext.Current.Server.MapPath


(FilePathName).ToString()); //创建文件
if(!CreateFile.Exists)
{
FileStream FS=CreateFile.Create();
FS.Close();
}
}
catch
{
}
}
/**////


/// 删除整个文件夹及其字文件夹和文件
///

///
public void DeleParentFolder(string FolderPathName)
{
try
{
DirectoryInfo DelFolder = new DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath


(FolderPathName).ToString());
if(DelFolder.Exists)
{
DelFolder.Delete();
}
}
catch
{
}
}
/**////


/// 在文件里追加内容
///

///
public void ReWriteReadinnerText(string FilePathName,string WriteWord)
{
try
{
//建立文件夹和文件
//CreateFolder(FilePathName);
CreateFile(FilePathName);
//得到原来文件的内容
FileStream FileRead=new FileStream(System.Web.HttpContext.Current.Server.MapPath


(FilePathName).ToString(),FileMode.Open,FileAccess.ReadWrite);
StreamReader FileReadWord=new StreamReader(FileRead,System.Text.Encoding.Default);
string OldString = FileReadWord.ReadToEnd().ToString();
OldString = OldString + WriteWord;
//把新的内容重新写入
StreamWriter FileWrite=new StreamWriter(FileRead,System.Text.Encoding.Default);
FileWrite.Write(WriteWord);
//关闭
FileWrite.Close();
FileReadWord.Close();
FileRead.Close();
}
catch
{
// throw;
}
}


/**////


/// 在文件里追加内容
///

///
public string ReaderFileData(string FilePathName)
{
try
{

FileStream FileRead=new FileStream(System.Web.HttpContext.Current.Server.MapPath


(FilePathName).ToString(),FileMode.Open,FileAccess.Read);
StreamReader FileReadWord=new StreamReader(FileRead,System.Text.Encoding.Default);
string TxtString = FileReadWord.ReadToEnd().ToString();
//关闭
FileReadWord.Close();
FileRead.Close();
return TxtString;
}
catch
{
throw;
}
}
/**////


/// 读取文件夹的文件
///

///
///
public DirectoryInfo checkValidSessionPath(string FilePathName)
{
try
{
DirectoryInfo MainDir = new DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath


(FilePathName));
return MainDir;

}
catch
{
throw;
}
}
}
}


来源:网络







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.