简体   繁体   English

尝试重命名文件时出错

[英]Error trying rename a file

Hi community! 社区大家好!

I have an application in VB.Net, in the user's computer is located in program files. 我在VB.Net中有一个应用程序,在用户计算机中位于程序文件中。 The users run always the program as an Administrators. 用户始终以管理员身份运行程序。

But in some cases; 但是在某些情况下; when the program try to rename a file in the program files the program throws the following exception: 当程序尝试重命名程序文件中的文件时,程序将引发以下异常:

The given path's format is not supported. 不支持给定路径的格式。 SOURCE = System.Security.Util.StringExpressionSet.CanonicalizePath 源= System.Security.Util.StringExpressionSet.CanonicalizePath

Also, happens when I try to copy a file. 另外,当我尝试复制文件时也会发生。

The application does the rename or copy automatically and it's the same name for all the users 该应用程序会自动进行重命名或复制,并且对所有用户都使用相同的名称

Example: 例:

Rename(vOld, vNew)
FileCopy(vOld, vNew)

This exception only happen in Win7. 此异常仅在Win7中发生。

Somebody have an idea what is the reason to some users appear this exception? 有人知道某些用户出现此异常的原因是什么?

This will happen when the user provides an invalid file name, for example one that includes colons. 当用户提供无效的文件名(例如,包含冒号的文件名)时,就会发生这种情况。

You should validate that the user-entered file name does not contain any of the values in System.IO.Path.GetInvalidPathChars . 您应该验证用户输入的文件名不包含System.IO.Path.GetInvalidPathChars中的任何值。

All it's my fault! 都是我的错!

-_-' -_-'

I'm trying to rename this path: 我正在尝试重命名此路径:

C:\_MyFile.xlsx

To: 至:

C:\MyFile.xlsx

In my computer all works fine because I have the both files (The users only has the file with the underscore). 在我的计算机上,一切正常,因为我同时拥有两个文件(用户只有带下划线的文件)。 When the program try to validate it try to rename the file "_C:\\MyFile.xlsx" to "C:\\MyFile.xlsx" 当程序尝试验证时,尝试将文件"_C:\\MyFile.xlsx"重命名为"C:\\MyFile.xlsx"

The exception don't give much information about my error... 异常没有提供有关我的错误的太多信息...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM