Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 10th, 2007, 01:57 PM
Friend of Wrox
 
Join Date: Dec 2006
Location: , , .
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
Default write to file

hi expert
i used System.IO.StreamWriter in my application to create a file,

i creat my favorite file and i write my data in it,

my problem is that any user by any permision on windows whos open my created file by notPade , my data shows to him(her),

i want to imposible read and write to my file exept by my application

please help me
best refagrds
  #2 (permalink)  
Old March 24th, 2007, 06:58 AM
Registered User
 
Join Date: Mar 2007
Location: , , Netherlands.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Take a look at this method:

using System.Security.AccessControl;
using System.IO;


Private void ProtectFile(string FileName, bool Protect)
{

FileSecurity fileSecurity = new FileSecurity();


If (Protect == true)
{
fileSecurity.SetAccessRuleProtection(true,true);
}
Else if (Protect == false)
{
fileSecurity.SetAccessRuleProtection(false,false);
}

FileInfo fileInfo = new FileInfo(FileName);

fileInfo.SetAccessControl(fileSecurity);

}


  #3 (permalink)  
Old March 24th, 2007, 02:07 PM
Friend of Wrox
 
Join Date: Dec 2006
Location: , , .
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
Default

great apperciation dear JanWillemKL
i have a question
is it possible to cancle this protect by users on windows?
in fact i want to know is this a best good to protect file(s)?

thank again
  #4 (permalink)  
Old March 24th, 2007, 06:22 PM
Registered User
 
Join Date: Mar 2007
Location: , , Netherlands.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It's possible the same way you do. They can write their own application. But this method in combination with encoding doesn't make it easy to read!

  #5 (permalink)  
Old March 25th, 2007, 05:01 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You can also simplify the code somewhat:
Code:
private void ProtectFile(string fileName, bool protect)
{
  FileSecurity fileSecurity = new FileSecurity();
  fileSecurity.SetAccessRuleProtection(protect, protect);
  FileInfo fileInfo = new FileInfo(fileName);            
  fileInfo.SetAccessControl(fileSecurity);
}
--

Joe (Microsoft MVP - XML)
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simultaneous file write jmjlm VBScript 4 May 25th, 2007 04:41 PM
Write an Excel File. dpkbahuguna ASP.NET 2.0 Basics 4 March 9th, 2007 05:20 AM
write file abaso.jadhav01 ASP.NET 2.0 Basics 0 November 24th, 2006 06:15 PM
why does this over write the previous file starsailor Pro JSP 0 December 6th, 2004 03:53 PM
reading HTML from file -> write to file mikeuk Beginning PHP 4 July 21st, 2004 05:40 AM



All times are GMT -4. The time now is 01:44 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.