导航:首页 > 版本升级 > net将文件移动

net将文件移动

发布时间:2025-02-12 02:37:34

① .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:别忘了引入专命名属空间

阅读全文

与net将文件移动相关的资料

热点内容
如何将文件压缩成图片 浏览:598
怎么避开行程卡大数据 浏览:839
法学类专业题可用什么app扫 浏览:844
prt转pdf文件 浏览:637
小米4怎么电脑传文件 浏览:22
5s哪个版本支持三网通 浏览:987
导航升级不换主程序 浏览:435
数据库mergesort 浏览:870
扫描的文件怎么保存到电脑 浏览:657
不能打开设备和打印机共享文件 浏览:239
唱鸭一般下载在哪个文件 浏览:540
看一些特殊电影的app有哪些 浏览:282
jsp程序配置文件 浏览:781
coc7本升级顺序 浏览:596
linux怎么写文件 浏览:337
最完美教程word2010论文排版技巧 浏览:382
就需要检查该文件是否正确 浏览:320
iphone文件夹改名字怎么改回来 浏览:577
百度云怎么找回删除文件 浏览:76
查表一共有多少数据 浏览:158

友情链接