将图像从一个文件夹移动到另一个文件夹?

时间:2016-05-05 13:44:19

标签: c# asp.net save

我的项目中有两个文件夹,文件夹“Images”是一个名为“FingerprintScan.jpg”的文件。我要做的是获取此文件,然后将其保存在名为“FingerPrints”的其他文件夹中。

我正在使用的代码不会抛出任何错误,据我所知,逻辑上应该没有任何反应。

string fileName = "FingerprintScan.JPG";
string newfilename = TextBoxUsername.Text + LabelStudentID.Text + ".JPG";
string appPath1 = AppDomain.CurrentDomain.BaseDirectory + @"Images\";
string appPath2 = AppDomain.CurrentDomain.BaseDirectory + @"FingerPrints\";

string sourceFile = System.IO.Path.Combine(appPath1, fileName);
string destFile = System.IO.Path.Combine(appPath2, newfilename);

System.IO.File.Copy(sourceFile, destFile, true);

我尝试过使用@"~\Images\@"Images,但没有运气。

1 个答案:

答案 0 :(得分:0)

尝试此组合并确保您的目录名称和源文件名与物理目录和文件匹配

string appPath1 = AppDomain.CurrentDomain.BaseDirectory + "Images";
string appPath2 = AppDomain.CurrentDomain.BaseDirectory + "FingerPrints";