是否有可能防止生成的ZIP文件被重命名

huangapple go评论76阅读模式
英文:

is this possible to prevent renaming the generated zip file

问题

使用以下代码,我正在生成一个名为result.zip的ZIP文件。是否可以防止重新命名此文件。用户不应该能够重新命名此文件。

string startPath = @"C:\TEMP\PS";//要添加到ZIP文件的文件夹路径
string zipPath = @"C:\TEMP\result.zip";//ZIP文件的路径
ZipFile.CreateFromDirectory(startPath, zipPath, CompressionLevel.Fastest, true);
英文:

With below code I am generating a zip file name = result.zip. Is this possible to prevent re-naming this file. User should not be able to re-name this file.

string startPath = @"C:\TEMP\PS";//folder to add
string zipPath = @"C:\TEMP\result.zip";//ZIP file path
ZipFile.CreateFromDirectory(startPath, zipPath, CompressionLevel.Fastest, true);

答案1

得分: 2

唯一让我想到的是,如果在创建文件后将其设置为只读。如果用户拥有足够的权限,他们可以通过移除只读属性来重命名它。他们仍然可以重命名它,但这对他们来说会更加困难。如果以后需要再次写入它,您的代码需要首先移除只读属性。甚至可能将其设置为隐藏。据我所知,没有理想的解决方案。

英文:

The only thing that springs to mind is if you make the file read only after you create it. If the user has enough permissions, they could rename it only by removing the read only attribute. They can still rename it, but it would be harder for them. If you have to write to it again later you would need your code to first remove the read only attribute. Maybe even make it hidden. There isn't an ideal solution that I am aware of.

https://stackoverflow.com/questions/8081242/c-sharp-make-file-read-write-from-readonly

huangapple
  • 本文由 发表于 2023年2月24日 14:34:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75553275.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定