asp復制文件夾
① 使用asp.net如果進行文件的復制
給你寫一個方法吧
public void CopyFile(string SourceFile, string ObjectFile)
{
string sourceFile = Server.MapPath(SourceFile);
string objectFile = Server.MapPath(ObjectFile);
if (System.IO.File.Exists(sourceFile))
{
System.IO.File.Copy(sourceFile, objectFile, true);
}
}
你可以到處引用這個就行了
② asp中fso復制文件夾
使用fso.CopyFolder.如果你的page在fullpath下,根據用戶名來創建的文件夾也在fullpath下,那麼假設新建的文件夾名稱為UserFolder,那麼:
fso.CoypFolder(fullpath&"page",fullpath&"\"&UserFolder&"\")
細節方面自己測試一下,如果你的fullpath本身已經包含"\",取消上面的斜杠就可以了.如果直接在ASP代碼里寫(不是腳本),需要把參數兩邊的括弧去掉.
③ ASP復制文件夾代碼
<%
Function CopyMyFolder(FolderName,FolderPath)
sFolder=server.mappath(FolderName)
oFolder=server.mappath(FolderPath)
set fso=server.createobject("scripting.filesystemobject")
if fso.folderexists(server.mappath(FolderName)) Then'檢查原文件夾是否存在
if fso.folderexists(server.mappath(FolderPath)) Then'檢查目標文件夾是否存在
fso.folder sFolder,oFolder
Else '目標文件夾如果不存在就創建
CreateNewFolder = Server.Mappath(FolderPath)
fso.CreateFolder(CreateNewFolder)
fso.folder sFolder,oFolder
End if
CopyMyFolder="復制文件夾["&server.mappath(FolderName)&"]到["&server.mappath(FolderPath)&"]成功!"
Else
CopyMyFolder="錯誤,原文件夾["&sFolde&"]不存在!"
End If
set fso=nothing
End Function
FolderName="原文件夾"
FolderPath="目標文件夾"
response.write""&CopyMyFolder(FolderName,FolderPath)&""
%>
④ 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來實現復制文件夾功能
以下是代碼:<% sFolder=server.mappath(FolderName) oFolder=server.mappath(FolderPath) set fso=server.createobject("scripting.filesystemobject") if fso.folderexists(server.mappath(FolderName)) Then'檢查原文件夾是否存在 if fso.folderexists(server.mappath(FolderPath)) Then'檢查目標文件夾是否存在 fso.folder sFolder,oFolder Else '目標文件夾如果不存在就創建 CreateNewFolder = Server.Mappath(FolderPath) fso.CreateFolder(CreateNewFolder) fso.folder sFolder,oFolderEnd ifCopyMyFolder="復制文件夾["&server.mappath(FolderName)&"]到["&server.mappath(FolderPath)&"]成功!"ElseCopyMyFolder="錯誤,原文件夾["&sFolde&"]不存在!"End Ifset fso=nothing End Function FolderName="2006" '原文件夾 FolderPath="2008" '目標文件夾
⑥ asp 如何 批量的復制指定目錄下的文件夾 到指定的目錄
思路:
1.用 System.IO.Directory.GetFiles() 方法獲得所有文件
2.生成一個泛型列表 List<System.IO.FileInfo> ,然後遍歷上面找到的文件並生成 System.IO.FileInfo 對象加入上面的列表。
3.完成
上面的泛型列表可以在最終的Web作為數據綁定用。
⑦ ASP.NET中怎麼把一個文件夾內的一個文件復制傳到另外一個文件夾內(原文件還在)
//新目錄
string newPath ="c:\\";
FileInfo fi = new FileInfo("F:\\xx.js");
//判斷目錄是否存在
if(!Directory.Exists(newPath))
{
Directory.CreateDirectory(newPath);
}
//復制文件
fi.CopyTo(newPath + fi.Name);
⑧ asp.ASP.NET 怎麼把外部圖片復制粘貼到項目文件
stringname=FileUpload1。PostedFile。FileName;//客戶端文件路徑FileInfofile=newFileInfo(name);。
項目之間不可以直接復制圖片和源文件的。
ASP。NET又稱為ASP+,不僅僅是ASP的簡單升級,而是微軟公司推出的新一代腳本語言。