利用 File.GetAttributes 返回值时遇到的小插曲

今天写了段下载文件的代码,由于一些文件是只读属性,因此需要 File.GetAttributes 来判断其属性并更改,于是直接写了 if(File.GetAttributes(Server.MapPath(filedownloadname) == FileAttributes.ReadOnly) 
      File.SetAttributes(Server.MapPath(filedownloadname),FileAttributes.Archive);

结果在使用时,只读状态并不能被更改,调试时发现File.GetAttributes(Server.MapPath(filedownloadname ) 返回的是数值,虽然可以用 File.GetAttributes(Server.MapPath(filedownloadname ) & FileAttributer.ReadOnly 解决,但怎么样才能得到字符值呢?在多次实验后,发现如果是
string filedownloadname = @"xxx\xxx.xx" ;
File.GetAttributes(filedownloadname) 取出的便是字符值了。

你可能感兴趣的:(attribute)