Wrox Programmer Forums
|
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
 
Old March 10th, 2007, 01:57 PM
Friend of Wrox
 
Join Date: Dec 2006
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
 
Old March 24th, 2007, 06:58 AM
Registered User
 
Join Date: Mar 2007
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);

}


 
Old March 24th, 2007, 02:07 PM
Friend of Wrox
 
Join Date: Dec 2006
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
 
Old March 24th, 2007, 06:22 PM
Registered User
 
Join Date: Mar 2007
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!

 
Old March 25th, 2007, 05:01 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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)





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





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