Changing File Permissions


i have file want copy different location. files marked readonly. want change permission not read , copy file , change permission back. there way handle this?

 

here how detect attribute:

 

string file = @"c:\file.jpg";

fileinfo info = new fileinfo( file );

if( (info.attributes & fileattributes.readonly) != 0 )

console.writeline( "read only" );

else

console.writeline( "nope" );

 

little explain.

if don't care other atributes (hidden, archve etc.) can make this:

info.attributes = fileattributes.normal;

info.attributes = fileattributes.readonly;

but if don't want to change other attributes must bitwise operations and

here little explain:

| (or) make this   101 | 010 = 111 or 111 | 010 = 111

and

^ (xor) make 111 ^ 010 = 101

so, when are removing some attribute you must sure, attribute set before you can remove it.

markku



Archived Forums V  >  Visual C# Language



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'