導航:首頁 > 版本升級 > 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將文件移動相關的資料

熱點內容
電腦版上傳視頻找不到文件在哪 瀏覽:164
javastringtemplate 瀏覽:594
聯想啟天m7300能升級內存嗎 瀏覽:698
精雕怎麼打開圖片文件 瀏覽:161
ug編程鏜孔g76如何使用 瀏覽:719
7歲到18歲少兒編程學什麼 瀏覽:413
mac文件怎麼列印 瀏覽:756
農葯登記許可證查詢哪個網站 瀏覽:857
素材站用什麼網站系統 瀏覽:173
ug如何用鉸刀編程 瀏覽:647
三國志版本介紹 瀏覽:260
情侶用的定位app有哪些 瀏覽:244
怎麼清楚蘋果手機的健身數據 瀏覽:988
淘寶美工教程自學網 瀏覽:452
父子2006未刪減版本 瀏覽:872
包頭誰賣蘋果6 瀏覽:504
化工企業停工有哪些文件通知要求 瀏覽:878
下載軟體後文件夾在桌面 瀏覽:397
word文字編組 瀏覽:167
旅遊策劃的程序 瀏覽:519

友情鏈接