asp.net 文件 操作方法

 1         /// <summary>
 2         /// 移动文件
 3         /// </summary>
 4         /// <param name="oldPath">源文件路径</param>
 5         /// <param name="newPath">目标文件路径</param>
 6         /// <param name="fileName">文件名称</param>
 7         public static void MoveFile(string oldPath, string newPath, string fileName)
 8         {
 9             if (!Directory.Exists(newPath))
10             {
11                 //不存在则自动创建文件夹
12                 Directory.CreateDirectory(newPath);
13             }
14             File.Move(oldPath + fileName, newPath + fileName);
15         }
16
17         /// <summary>
18         /// 批量移动文件
19         /// </summary>
20         /// <param name="oldPath">源文件路径</param>
21         /// <param name="newPath">目标文件路径</param>
22         /// <param name="fileNameList">文件名称</param>
23         public static void MoveFile(string oldPath, string newPath, ArrayList fileNameList)
24         {
25             if (!Directory.Exists(newPath))
26             {
27                 //不存在则自动创建文件夹
28                 Directory.CreateDirectory(newPath);
29             }
30             for (int i = 0; i < fileNameList.Count; i++)
31             {
32                 File.Move(oldPath + fileNameList[i], newPath + fileNameList[i]);
33             }
34         }
35
36         /// <summary>
37         /// 删除文件
38         /// </summary>
39         /// <param name="path">文件路径</param>
40         /// <returns>删除结果,成功或失败</returns>
41         public static bool DeleteFile(string path)
42         {
43             try
44             {
45                 File.Delete(path);
46                 return true;
47             }
48             catch
49             {
50                 return false;
51             }
52         }
53
54         /// <summary>
55         /// 删除文件夹
56         /// </summary>
57         /// <param name="path">文件夹路径</param>
58         /// <returns>删除结果,成功或失败</returns>
59         public static bool DeleteFolder(string path)
60         {
61             try
62             {
63                 Directory.Delete(path);
64                 return true;
65             }
66             catch
67             {
68                 return false;
69             }
70         }
71
72         /// <summary>
73         /// 移动文件夹
74         /// </summary>
75         /// <param name="oldPath">源文件夹路径</param>
76         /// <param name="newPath">目标文件夹路径</param>
77         /// <returns>移动结果</returns>
78         public static bool MoveFolder(string oldPath, string newPath)
79         {
80             try
81             {
82                 Directory.Move(oldPath, newPath);
83                 return true;
84             }
85             catch
86             {
87                 return false;
88             }
89         }    
时间: 2024-08-06 07:55:35

asp.net 文件 操作方法的相关文章

Asp.Net 文件操作基类

using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.T

你以为的ASP.NET文件上传大小限制是你以为的吗

我们以为的文件大小限制 我们大家都知道ASP.NET为我们提供了文件上传服务器控件FileUpload,默认情况下可上传的最大文件为4M,如果要改变可上传文件大小限制,那么我们可以在web.config中的httpRuntime元素中添加maxRequestLength属性设置大小,同时为了支持大文件上传超时可以添加executionTimeout属性设置超时时间.网上有很多这样的例子,但实际情况是否是这样吗? <httpRuntime maxRequestLength="" e

文件操作方法fscanf

直入主题,首先把经典方法放在前面: 如下情况大量有规律的数据存储在文件中格式化的读取方法: Almond #EED9C4 Antique Brass #C88A65 Apricot #FDD5B1 Aquamarine #71D9E2 Asparagus #7BA05B ............................. 先上代码: 1 FILE *fp; //定义文件指针 2 char a[20]={0}; //定义两个数组来接受数据 3 char b[20]={0}; 4 5 fp=

ASP.NET文件操作通用类

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 using System.IO; 7 using System.Web; 8 using System.Web.UI; 9 using System.Web.UI.WebControls; 10 11 12 public class WebFileHelper 13 { 14 15 FileInfo f

asp.net 文件批量选取,批量上传,带进度条,uploadify3.2 TOP

http://www.16aspx.com/Article/3444 asp.net 文件批量选取,批量上传,带进度条,uploadify3.2 TOP,布布扣,bubuko.com

asp.net文件操作类

/** 文件操作类 **/ #region 引用命名空间 using System; using System.Collections.Generic; using System.Text; using System.IO; #endregion namespace CommonUtilities { /// <summary> /// 文件操作类 /// </summary> public class FileHelper { #region 检测指定目录是否存在 /// <

asp.net 文件上传出错:Maximum request length exceeded 解决方法

<configuration>    <system.web>               <httpRuntime maxRequestLength="102400" useFullyQualifiedRedirectUrl="true" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="10

asp.Net文件的上传下载(2) 转

Asp.net 上传.下载文件 2011-01-08 16:21:48|  分类: .NET |  标签: |举报 |字号大中小 订阅 首先我们要判断用户是否选择了要上传文件,我们可用下面这句实现: if(File1.PostedFile.ContentLength>0)  如果用户有上传的文件,则:   string name = File1.PostedFile.FileName ;//获取输入的文件名字      int i= name.LastIndexOf(".") ;

C#File类常用的文件操作方法(创建、移动、删除、复制等)

File类,是一个静态类,主要是来提供一些函数库用的.静态实用类,提供了很多静态的方法,支持对文件的基本操作,包括创建,拷贝,移动,删除和 打开一个文件. File类方法的参量很多时候都是路径path.File的一些方法可以返回FileStream和StreamWriter的对象.可以 和他们配套使用.System.IO.File类和System.IO.FileInfo类 主要提供有关文件的各种操作,在使用时需要引用System.IO命名空间. 一.File类常用的操作方法 1.创建文件方法 /