C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Programmatically deny the Read permission on a file


Posted Date: 12 Mar 2007    Resource Type: Code Snippets    Category: Security

Posted By: Balamurali Balaji       Member Level: Diamond
Rating:     Points: 10



The following code denies the Read permission for a file.



string filename = @"d:\balamurali\bb.txt";
System.Security.Permissions.FileIOPermission permission = new
System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.Read ,filename);

try
{
permission.Deny();
System.IO.StreamReader sr = new System.IO.StreamReader(filename);
MessageBox.Show(sr.ReadToEnd());

}
catch (System.Security.SecurityException ex)
{
MessageBox.Show("Permission to read the file was denied " );
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}






Responses

Author: Raj Kumar Prajapati    27 Aug 2008Member Level: Bronze   Points : 0
ITS WORKING
THANKS
RAJ PRAJAPATI


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Encrypt & Decrypt a string - Data Encryption Standard (DES)
Previous Resource: Check if the current windows user has Administrator rights
Return to Discussion Resource Index
Post New Resource
Category: Security


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

it help desk

Contact Us    Privacy Policy    Terms Of Use