如何确认文件是否可编辑 [英] How to be confirm is a file editable or not

查看:101
本文介绍了如何确认文件是否可编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须检查文件路径.有什么方法可以授予或不授予特定文件路径的用户权限?通常,我是否可以使用C#代码获取有关文件是否可编辑的任何信息?

I have to check a file with the file path. Is there any way to get the user permission granted or not for that particular file path? In generally, can i get any information is the file is editable or not using C# code?

推荐答案

绝对检查文件是否可以编辑的唯一方法是:在try...catch块中打开一个用于读取/写入的流.如果没有收到异常,则该异常是可编辑的.请记住在完成检查后立即关闭并处置流,否则由于检查代码已将其锁定而无法使用它!

但是,这不会阻止文件立即变为不可用! (实际上,在某些系统中,由于某些备份系统会监视文件访问并立即获取文件以进行备份,因此它可能更可能在之后被首先使用.
The only way to absolutely check if a file can be edited is to open a stream for read/write, within a try...catch block. If you don''t get an exception, it is editable. Remember to Close and Dispose the stream immediately you are finished checking, or it will not be available because the check code has locked it!

However, that does not stop the file becoming unavailable immediately afterwards! (In fact, in some systems, it may make it more likely top be in use afterwards, as some backup systems watch for file access and immediately grab the file for backing up...


检查文件是否为只读 [
Check the file is readonly[^]


这篇关于如何确认文件是否可编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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