① .NET winfrom中如何将文件移动到某个文件夹
System.IO.File
类中有相关静态方法,制定源及目标就可以实现复制,移动,删除等操作。
② asp.net如何实现将服务器上的文件下载到本地
给你提供一抄点代码:
string fileURL = this.Server.MapPath("你要下载袭的文件路径");//文件路径,可用相对路径
FileInfo fileInfo = new FileInfo(fileURL);
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=" + Server.UrlEncode(fileInfo.Name.ToString()));//文件名
Response.AddHeader("content-length", fileInfo.Length.ToString());//文件大小
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.WriteFile(fileURL);
③ asp.net 如何将一个目录下的所有文件复制到另一个目录里面。
private void CopyFile(string sources, string dest)
{
DirectoryInfo dinfo=new DirectoryInfo(sources);//注,这里面传的是路径,并不是文件,所以不能保含带后缀的文件
foreach(FileSystemInfo f in dinfo.GetFileSystemInfos())
{
//目标路径destName = 目标文件夹路径 + 原文件夹下的子文件(或文件夹)名字
//Path.Combine(string a ,string b) 为合并两个字符串
String destName = Path.Combine(dest, fsi.Name);
if (f is FileInfo)//如果是文件就复制
{
File.Copy(f.FullName, destName, true);//true代表可以覆盖同名文件
}
else//如果是文件夹就创建文件夹然后复制然后递归复制
{
Directory.CreateDirectory(destName);
CopyFile(f.FullName, destName);
}
}
}
④ ASP.NET如何将文件由一个文件夹转移到另一个文件夹
给你个例子,代码比较乱,凑合看看吧
string path = @"c:\temp\MyTest.txt";
string path2 = @"c:\temp2\MyTest.txt";
try
{
if (!File.Exists(path))
{
throw new Exception("file not exist");
}
// Ensure that the target does not exist.
if (File.Exists(path2))
File.Delete(path2);
// Move the file.
File.Move(path, path2);
Console.WriteLine("{0} was moved to {1}.", path, path2);
// See if the original exists now.
if (File.Exists(path))
{
Console.WriteLine("The original file still exists, which is unexpected.");
}
else
{
Console.WriteLine("The original file no longer exists, which is expected.");
}
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
⑤ asp.net如何将一个文件里指定文件命的文件复制到另一个文件夹里
string OrginFile,NewFile;
OrginFile=Server.MapPath(".")+"\\myText.txt"; //文件原始路径
NewFile=Server.MapPath(".")+"\\myTextCoyp.txt";//要放的路径
File.Move(OrginFile,NewFile);
PS:别忘了引入专命名属空间