我正在创建应用程序。在那个,我把组合框,组合框填入申请号。来自db。在组合框的选择上,网格填充了驱动器中另一台机器中的文件。与//user/public/af001/edit/test.JPEG
一样,在网格中,我将下载链接放在特定行上,以便在我的计算机上下载该文件,但问题是当我下载该文件时,我没有考虑//user/public/af001/edit/test.JPEG
。
if (e.Column Index == 0)
{
int row;
//Get the row index
row = e.Row Index;
string old Path = @"~\\Users\Public\AS\AFS1402190001\Edit\test.JPEG";
string new path = @"E:\example\";
string new File Name = "new file name";
File Info f1 = new File Info(old Path);
if (f1.Exists)
{
if (!Directory.Exists(new path))
{
Directory.Create Directory(new path);
}
f1.Copy To(string.Format("{0}{1}{2}", new path, new File Name, f1.Extension));
}
}
你能告诉我这是什么问题吗?
感谢您的帮助。
答案 0 :(得分:0)
问题出在这一行:
string.Format("{0}{1}{2}", new path, new File Name, f1.Extension);
它看起来你没有构建正确的文件补丁。尝试使用System.IO.Path.Combine
来组合目录和fileName。类似的东西:
System.IO.Path.Combine(dirPath, string.Format("{0}.{1}", fileName, extension));
当然,您可能希望确保路径/文件名没有无效字符,您可以使用System.IO.Path.GetInvalidFileNameChars()
和System.IO.Path.GetInvalidPathChars()
来获取您需要避免的非法字符。