ASP.NET对文件的操作
来源:互联网 发布:华中师范大学网络课程 编辑:程序博客网 时间:2024/05/24 01:42
//获取一个文件的大小
System.IO.FileInfo file = new System.IO.FileInfo("C:\\t.txt");
int fileSize = (int)file.Length / 1024;//把文件大小换算成KB
Response.Write("<script>alert(" + fileSize.ToString() + ");</script>");
-------------------------------------------------------------------------
-------创建文件夹using System.IO;
private void button2_Click(object sender, EventArgs e)
{
if (Directory.Exists("\\picture"))//判断一个文件夹是否存在
{
MessageBox.Show("directory exists");
}
else {
//创建一个文件夹
Directory.CreateDirectory("\\picture");
}
}
Directory.Delete(path,true);//删除一个文件夹,其中path是文件夹的绝对路径
---------------------打开一个文件
Process.Start("C:\\t.txt");//打开一个文件
public void Page_Load(Object src,EventArgs e)
{
StreamWriter rw = File.CreateText(Server.MapPath(".")+"[url=file://mytext.txt/]\\myText.txt[/url]");
rw.WriteLine("追逐理想");
rw.WriteLine("kzlll");
rw.WriteLine(".NET笔记");
rw.Flush();
rw.Close();
}
打开文本文件
StreamReader sr = File.OpenText(Server.MapPath(".")+"[url=file://mytext.txt/]\\myText.txt[/url]");
StringBuilder output = new StringBuilder();
string rl;
while((rl=sr.ReadLine())!=null)
{
output.Append(rl+"<br>");
}
lblFile.Text = output.ToString();
sr.Close();
C#追加文件
StreamWriter sw = File.AppendText(Server.MapPath(".")+"[url=file://mytext.txt/]\\myText.txt[/url]");
sw.WriteLine("追逐理想");
sw.WriteLine("kzlll");
sw.WriteLine(".NET笔记");
sw.Flush();
sw.Close();
C#拷贝文件
string OrignFile,NewFile;
OrignFile = Server.MapPath(".")+"[url=file://mytext.txt/]\\myText.txt[/url]";
NewFile = Server.MapPath(".")+"[url=file://mytextcopy.txt/]\\myTextCopy.txt[/url]";
File.Copy(OrignFile,NewFile,true);
C#删除文件
string delFile = Server.MapPath(".")+"[url=file://mytextcopy.txt/]\\myTextCopy.txt[/url]";
File.Delete(delFile);
C#移动文件
string OrignFile,NewFile;
OrignFile = Server.MapPath(".")+"[url=file://mytext.txt/]\\myText.txt[/url]";
NewFile = Server.MapPath(".")+"[url=file://mytextcopy.txt/]\\myTextCopy.txt[/url]";
File.Move(OrignFile,NewFile);
C#创建目录
// 创建目录c:\sixAge
DirectoryInfo d=Directory.CreateDirectory("c:\\sixAge");
// d1指向c:\sixAge\sixAge1
DirectoryInfo d1=d.CreateSubdirectory("sixAge1");
// d2指向c:\sixAge\sixAge1\sixAge1_1
DirectoryInfo d2=d1.CreateSubdirectory("sixAge1_1");
// 将当前目录设为c:\sixAge
Directory.SetCurrentDirectory("c:\\sixAge");
// 创建目录c:\sixAge\sixAge2
Directory.CreateDirectory("sixAge2");
// 创建目录c:\sixAge\sixAge2\sixAge2_1
Directory.CreateDirectory("sixAge2\\sixAge2_1");
- ASP.NET 对文件的操作
- Asp.Net对Xml文件的操作
- Asp.Net对Xml文件的操作
- Asp.Net对Xml文件的操作
- ASP.net 对XML文件的操作
- ASP.NET对文件的操作
- asp.net中对XML文件的简单操作
- asp.net对XML文件的一些简单操作
- Asp.Net对文件和文件夹的操作大全
- ASP.NET对XML文件的基本操作
- asp.net 文件的操作
- asp.net对数据库的操作
- asp.net对图片的操作
- ASP.NET中对cookie的操作
- asp.net 对XML的操作
- asp.net对cookie的操作
- asp.net对XML的操作
- asp.net 对Cookie的简单操作
- 整理的三星ARM芯片最新报价(比较全)
- 用post提交数据时不应该把参数放在url里,否则参数过长会提交失败。
- hdu 4123 Bob’s Race
- 杭电2099之整除的尾数
- 浅谈java异常[Exception]
- ASP.NET对文件的操作
- 获取谷歌地图 apiKey
- OpenCV 人脸检测自学(3)
- osgi的发展
- cocos2dx 不要直接在 onEnter 里面 addTargetedDelegate (或 addStandardDelegate)
- C语言习题练习集锦
- ckeditor中使用CKFinder时,记住上一次路径
- APK的反编译与编译(APKTOOL)
- osgi学习笔记4之 web客户端调用已发布的接口服务