6
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);

次の例外が生成されます。

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

ソース ディレクトリと宛先ディレクトリの両方が存在します。

4

2 に答える 2

27

宛先パスにコロン (:) がありますが、これは Windows では許可されていません (もちろん、ドライブ文字指定子の一部としては別として...)。

これを機能させるには、埋め込もうとしている日時にコロンを使用しない別の日付形式を選択します。

于 2012-12-17T16:51:41.943 に答える
4

これは、予約文字と、 Windowsファイルパスの作成時に許可または許可されないものを説明するMSDNサイトです。yyyymmddまたはmmddyyyyを使用するために日付部分も「_​​」再フォーマットする必要がある場合は、 「:」をアンダースコア に置き換えます。別のDateTime変数に格納され、それを文字列に変換します。使用できるオプションは他にもたくさんあります。

ファイル、パス、および名前空間の命名(Windows)

于 2012-12-17T16:59:33.233 に答える