473,414 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Folder remains readonly in C#

122 100+
I am creating a folder from my application and attempting to write from the filestream to the folder, however when I do I get an access denied exception. I have tried adding security rights to the folder/file however I have still had no success.

If you go to windows explorer and try to remove the read-only property it just stays there.

Please if anyone can help I would certainly appreciate it.
Mar 26 '07 #1
10 7954
vanc
211 Expert 100+
Haven't figured out the reason lead to your prob. Post your codes to have a glance.
Mar 26 '07 #2
AricC
1,892 Expert 1GB
I am creating a folder from my application and attempting to write from the filestream to the folder, however when I do I get an access denied exception. I have tried adding security rights to the folder/file however I have still had no success.

If you go to windows explorer and try to remove the read-only property it just stays there.

Please if anyone can help I would certainly appreciate it.
Are you an adiministrator in your environment? If not you may not be able to change properties of a folder.
Mar 27 '07 #3
DragonLord
122 100+
Are you an adiministrator in your environment? If not you may not be able to change properties of a folder.
I am an administrator and can do everything on my machine including marking folders as readonly and vice versa except the one generated by the c# code.

Expand|Select|Wrap|Line Numbers
  1.  
  2.    // Specify the directory you want to manipulate.
  3.                 string path = @"C:\Program Files\TestDirectory";
  4.  
  5.                 try
  6.                 {
  7.                     // Determine whether the directory exists.
  8.                     if (Directory.Exists(path))
  9.                     {
  10.                         MessageBox.Show("That path exists already.");
  11.      return;
  12.                     }
  13.  
  14.                     // Try to create the directory
  15.  
  16.                     DirectoryInfo di = Directory.CreateDirectory(path);
  17.                     AddDirectorySecurity(path,"Dale", FileSystemRights.FullControl, AccessControlType.Allow);
  18.  
  19.  
  20. MessageBox.Show("The directory was created successfully at", Directory.GetCreationTime(path).ToString());
  21.  
  22.                 }
  23.                 catch (Exception ex)
  24.                 {
  25.                     MessageBox.Show("The process failed: {0}", e.ToString());
  26.                 }
  27.                 finally
  28.                 {
  29.                 }
  30.  
  31.  public static void AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
  32.         {
  33.             // Create a new DirectoryInfo object.
  34.             DirectoryInfo dInfo = new DirectoryInfo(FileName);
  35.  
  36.             // Get a DirectorySecurity object that represents the 
  37.             // current security settings.
  38.  
  39. DirectorySecurity dSecurity = dInfo.GetAccessControl();
  40.  
  41.             // Add the FileSystemAccessRule to the security settings. 
  42.             dSecurity.AddAccessRule(new FileSystemAccessRule(Account,
  43.                                                             Rights,
  44.                                                             ControlType));
  45.  
  46.             // Set the new access settings.
  47.             dI
  48. «MüÑÇhK!Ñ: RIP Mike« u knw wut...i always thought dogs...lay eggs says:
  49. // Set the new access settings.
  50.             dInfo.SetAccessControl(dSecurity);
  51.  
  52.         }
  53.  
  54.  
the create directory is mine, the AddDirectorySecurity was a sad attempt in removing the readonly property which never worked.

I was trying to understand the overloaded function for createdirectory (path,directorysecurity) but i have been yet to figure that out.

any help form the pro's would be greatly welcomed.
Mar 27 '07 #4
DragonLord
122 100+
// Set the new access settings.
dInfo.SetAccessControl(dSecurity);

sorry guys this should be the last part i used msn to transfer the code from one computer to another (wife is hoggin the development laptop!)
Mar 27 '07 #5
AricC
1,892 Expert 1GB
Is there a reason you reported this post?
Mar 30 '07 #6
DragonLord
122 100+
Nope sorry newbie with quick fingers figuring out how to use the forums
Mar 30 '07 #7
AricC
1,892 Expert 1GB
Nope sorry newbie with quick fingers figuring out how to use the forums
No problem did you find a solution?
Mar 30 '07 #8
developing
110 100+
if ur running ur prog from a networked dirve, then yeah this wont work. destination and source need to be on the same machine
Mar 31 '07 #9
DragonLord
122 100+
Nope sorry newbie with quick fingers figuring out how to use the forums
Mar 31 '07 #10
DragonLord
122 100+
No problem did you find a solution?
nope i didn't figure it out yet, it is not on a network drive though and i still can't figure it out.
Apr 5 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: WhiteEagl | last post by:
I am creating an installer for our .NET application. The installer creates different directories on the users computer. The problem is, when the application is installed by the windows...
1
by: Eike | last post by:
Hi, I am unable to delete a subfolder that I have created programatically. I am using a modification of the apiSHFileOperation by Dev Ashish (http://www.mvps.org/access/api/api0026.htm) to copy...
1
by: bcanavan | last post by:
I'm trying to link a remote client Access app (through the internet) to an mdb in a web folder on my web server. The idea is to give users readOnly access to the web folder mdb, which itself links...
2
by: Patty O'Dors | last post by:
I'm trying to write a function that determines whether a directory can be written to, short of trying to create a file and catching the exception, is there any fancier way of doing it? I tried...
4
by: Pavel | last post by:
Hello. I am trying to make a folder compressed and failing miserably. Below are three ways that I tried to make it compressed, all of them compile and run w/o any problems, but the folder is...
0
by: Dennis | last post by:
I have a shared folder on my network of 2 computers, "\\computer2\sharedocs" that has sharing set to read and write both. When I use new DirectoryInfo("\\computer2\sharedocs"), I get the value of...
1
by: Phil Haddock | last post by:
Can anyone post a code snippet on how to retrieve Permission information on a Folder? (Visual Basic 2005) There's lot's of information on how to set a permission, but I can't figure out how to...
24
by: biganthony via AccessMonster.com | last post by:
Hi, I have the following code to select a folder and then delete it. I keep getting a Path/File error on the line that deletes the actual folder. The line before that line deletes the files in...
5
by: Sin Jeong-hun | last post by:
Hello. Speical folders, like Desktop, usually have different display names. For example, in Japanese Windows, it's displayed as "$B%G%9%/%H%C%W(B". I want to get the this displayed name of a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.