gof*_*net 4 asp.net asp.net-3.5
我正在网站上工作,我想将文件从我的应用程序文件夹复制到同一服务器上的其他文件夹(但是这个文件夹不在我的应用程序文件夹中,即我在C驱动程序上的应用程序和目标文件夹在D驱动器上).Is这可能使用Asp.Net的任何功能?
提前致谢.
是的,有必要注意的唯一问题是CopyTo路径应该是完整路径,而不是相对路径(例如:c:\ websites\myOtherFolder).
这样,您就可以从ASP.NET代码中成功复制/移动文件.
下面是一个伪代码,向您展示如何完成它(假设该文件已放置在ASP.NET应用程序的根文件夹中).
using System.IO;
..
..
..
// Get the current app path:
var currentApplicationPath = HttpContext.Current.Request.PhysicalApplicationPath;
//Get the full path of the file
var fullFilePath = currentApplicationPath + fileNameWithExtension;
// Get the destination path
var copyToPath = "This has to be the full path to your destination directory.
Example d:\myfolder";
// Copy the file
File.Copy(fullFilePath , copyToPath );
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
32395 次 |
最近记录: |