Click here to Skip to main content
14,603,917 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am developing a window application of screen capturing for my company use. I want to capture the screen shoots and store those screen shots automatically in lock folder by programming. And after storing, i want to upload those screen shots on my company's server from that lock folder. so, I don't want to perform operations like delete, copy, paste on that folder. My problem is that, when I write Fullcontrol then I'm not able to store that screen shots in folder. So, Please tell me, how to do this? Which kind of access i have to give?

This is my code:
private void Permissionbtn_Click_1(object sender, EventArgs e)
    DirectoryInfo myDirectoryInfo = new DirectoryInfo(textBox1.Text);
    DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl();
    string User = System.Environment.UserDomainName + "\\" +
    myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(User,
    FileSystemRights.Read , AccessControlType.Deny));
    MessageBox.Show("Permissions Altered Successfully");
Updated 19-Feb-15 20:58pm
Rate this:
Please Sign up or sign in to vote.

Solution 1

My advice is not to mess with permission. This is the exercise for system administration. Doing it on temporary basis in a program is a bad thing. First, then that program should have certain permissions; too many assumptions. More importantly, someone else can use elevated permissions and mess with those files, or add more permissions to some user. So, what's the use?

Your purpose is different, you need the lock, with is a different thing. If a file is open for exclusive use (default), it is not accessible to other processes. Just keep all files open, close them on application exit. This is a simple and reliable method usually used in such cases.

Brinda Lakhani 20-Feb-15 3:26am
Thanx for solution. I understand that What you want say, but I can't do anything. Its the requirement of the client. This is one kind of software. When I install this software, It will capture the activity of the employee and upload that screen shots on the server.
Sergey Alexandrovich Kryukov 20-Feb-15 10:47am
What exactly is that "requirement of the client"? Can you formulate it?
Mohammad Reza Valadkhani 21-Feb-15 4:09am
handling permission is not recommended! ( I already have problem with that), why you not using something like encryption or also use encrypted compression on your files then send it to server! it`s also decrease the file size.
if i were you i use temp folder for saving screenshots based on encryption and at the end compress the folder then send. user may not access to your temp during the process because it`s open and also your screenshots is encrypted.

It`s an idea that comes to my mind. i hope it`s help you
Encryption is not making no access and is more complex...
Rate this:
Please Sign up or sign in to vote.

Solution 2

You can use FileStream.Lock and FileStream.UnLock for locking the file.

Check out this article on MSDN for Lock :

Check out this article on MSDN for UNLock :

Hope this helps!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100