导航:首页 > 版本升级 > 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将文件移动相关的资料

热点内容
三星手机没网络怎么办 浏览:876
将用高级程序语言编写的源程序 浏览:68
查看已登录wifi密码 浏览:936
如何把手机中的文件放入u盘 浏览:773
初中编程学什么专业 浏览:624
怎么用电脑连手机网络 浏览:70
升级win10txwifi 浏览:946
word同步保存到本地文件 浏览:25
网站管理是什么工种 浏览:908
怎样在手机上编辑word文档文件名 浏览:795
实体店的华为数据线多少钱 浏览:21
广发applepay10 浏览:85
js对象作为参数 浏览:424
变态app在哪里下载 浏览:715
win10怎么清除所有文件夹 浏览:440
桌面文件夹推荐搜索 浏览:992
a6l数据线哪个品牌好 浏览:140
特斯拉app怎么买 浏览:403
怎么用软件找网站 浏览:492
怎么把微信里的文件写上内容 浏览:735

友情链接