英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论