C#File.Copy抛出异常"不支持&QUOT给定的路径的格式; [英] C# File.Copy throws exception "The given path's format is not supported"

查看:213
本文介绍了C#File.Copy抛出异常"不支持&QUOT给定的路径的格式;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string source = @"C:\Users\damanja\Desktop\Projects\RecStudentManagement\RecStudentManagement.Web\Reports\Templates\ContactInformationReport.xlsx";
string dest = @"C:\Users\damanja\Desktop\Projects\RecStudentManagement\RecStudentManagement.Web\Reports\Ran\damanja2012-12-17T10:14:02.0394885-06:00.xlsx";

File.Copy(source, dest, true);

生成此异常:

Produces this exception:

The given path's format is not supported.

堆栈跟踪:

at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
   at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
   at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
   at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
   at RecStudentManagement.Web.Reports.ExcelReport.CopyTemplate() in C:\\Users\\damanja\\Desktop\\Projects\\RecStudentManagement\\RecStudentManagement.Web\\Reports\\ExcelReport.cs:line 52
   at RecStudentManagement.Web.Reports.ExcelReport..ctor(String fileName) in C:\\Users\\damanja\\Desktop\\Projects\\RecStudentManagement\\RecStudentManagement.Web\\Reports\\ExcelReport.cs:line 35
   at RecStudentManagement.Web.Reports.ContactInformationReport..ctor(IEnumerable`1 students, IEnumerable`1 includedPrograms, String createdByULID, String fileName) in C:\\Users\\damanja\\Desktop\\Projects\\RecStudentManagement\\RecStudentManagement.Web\\Reports\\ContactInformationReport.cs:line 22
   at RecStudentManagement.Web.Controllers.ReportsController.ContactInformationCreate(ContactInformationSetUpViewModel vm) in C:\\Users\\damanja\\Desktop\\Projects\\RecStudentManagement\\RecStudentManagement.Web\\Controllers\\ReportsController.cs:line 99

源和目标目录存在。

Both the source and destination directories exist.

推荐答案

您有冒号(:)的目标路径,而Windows不允许(除了作为盘符说明的一部分,当然​​...)

You have colons (:) in the destination path, which Windows does not allow (apart from as part of the drive letter specifier, of course...).

要得到这个工作,选择不同的日期格式的日期,时间,你正在试图嵌入,不使用冒号。

To get this to work, pick a different date format for the date-time you are trying to embed, which does not use colons.

这篇关于C#File.Copy抛出异常"不支持&QUOT给定的路径的格式;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆