473,883 Members | 1,618 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check for "Write Access" on a file/folder in .NET

Hello All,
Our application write logs to a file in a folder. Before our application
starts writing to that file, I want to check if the current user has write
access to that file, for example, "c:\temp\LogFil e.txt".
I see several articles for setting file access permissions, getting file
access permissions for a given user or current user - but the current user
could also gain write access to the same file not just by explicit permssion
but also thru implicit permissions. for example, the current user may be in
a NT group which can have write access to that file - so this user also gets
write access.
How to check if the current user can have write access either thru explicit
or implcit permssions set on the folder/file?.

All the following articles below talk about retrieving explicit permssions
or setting permissions but nothing talks about checking if the user has
access to that file thru implicit permssions.
In short, I want to check if the current user has write access to the file
"c:\temp\LogFil e.txt".

Can someone help?

File.GetAccessC ontrol Method
http://msdn2.microsoft.com/en-us/lib...sscontrol.aspx

FileSecurity Class
http://msdn2.microsoft.com/en-us/lib...esecurity.aspx

FileSecurity Members
http://msdn2.microsoft.com/en-us/lib...y_members.aspx
Jan 3 '07 #1
1 8070
Open the file for 'write' access, with the statement wrapped in a try catch.

If the statement succeeds then the user has 'write' access.

If the statement throws an exception then inspect the exception to determine
the reason.
"Ganesh Muthuvelu" <Ga************ *@discussions.m icrosoft.comwro te in
message news:47******** *************** ***********@mic rosoft.com...
Hello All,
Our application write logs to a file in a folder. Before our application
starts writing to that file, I want to check if the current user has write
access to that file, for example, "c:\temp\LogFil e.txt".
I see several articles for setting file access permissions, getting file
access permissions for a given user or current user - but the current user
could also gain write access to the same file not just by explicit
permssion
but also thru implicit permissions. for example, the current user may be
in
a NT group which can have write access to that file - so this user also
gets
write access.
How to check if the current user can have write access either thru
explicit
or implcit permssions set on the folder/file?.

All the following articles below talk about retrieving explicit permssions
or setting permissions but nothing talks about checking if the user has
access to that file thru implicit permssions.
In short, I want to check if the current user has write access to the file
"c:\temp\LogFil e.txt".

Can someone help?

File.GetAccessC ontrol Method
http://msdn2.microsoft.com/en-us/lib...sscontrol.aspx

FileSecurity Class
http://msdn2.microsoft.com/en-us/lib...esecurity.aspx

FileSecurity Members
http://msdn2.microsoft.com/en-us/lib...y_members.aspx

Jan 3 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
715
by: Paul | last post by:
Hi, VB.NET is saying the file I am creating is in use by another process and won't complete its task of moving the file to the specified destination folder. Here is my code (the main bit anyway).... Private Sub LogChange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs) If e.ChangeType = WatcherChangeTypes.Created Then
9
4025
by: mallyonline | last post by:
I last posted to this group about 6 months ago and was very pleased by the excellent response I got and the great help offered to me. I am back this time with another request for your expert help on a bit of ASP code I use on my windows server 2003 with IIS6 machine. I would like the code below to display in different colours depending on the status of the page. I am looking to make the not logged in code appear red and the logged in...
1
5592
by: Darren Lew | last post by:
Hi there, I have this problem which is really driving me nuts for a couple of days. Glad if any help or suggestion is given Javascript will give me a pop-up error "Access is denied" when i try to load a simple xml file, which is in the server machine itself. The script is within a JSP page running apache tom-cat. I am running it with IE6 from an windows administrative acc straight on the server so there shouldn't be any access prob.
3
4401
by: Lauren Quantrell | last post by:
I'd like to use my Access 2K application to write some text in the file properties of a Windows file. The properties I'm talking about are the properties you see whn you right click on a Windows file and then click on Properites, then the Summary tab. I want to be able to modify the Subject line and the Comments line in particular. I'm hoping someone can tell me how to do this. Thanks, lq
6
12594
by: Rob R. Ainscough | last post by:
I'm not sure why I'm getting this error when searching thru my local hard drives using My.Computer.FileSystem.GetFiles? I've got FileIOPermissions set in code: Dim f As New FileIOPermission(PermissionState.Unrestricted) f.AllFiles = FileIOPermissionAccess.AllAccess But I still get this error? Any work arounds to this?
12
1966
by: Dr. Edmund M. Hayes | last post by:
I wrote a access program that works well enough that a handful of people would like to buy it from me. My problem is that if I sell it to someone there is no mechanism that I know of to protect them from giving it to anyone they feel like. The program produces reports that are specific to a particular organization but that does stop anyone from just modifying that report to make it specific to another organization, who they might have...
0
1195
by: Michelle Monty | last post by:
Hi, I'm trying to create a program where the user can enter check information and the information is saved to a sequential access file. I'm getting an error when I run the program. The error is "Object reference not set to an instance of an object" and I'm getting it on the line that I have the ***** in front of below. Can anyone help me figure out how to fix this error? Thanks for your help. Here's my code: Option Explicit On Option...
2
1547
by: Michelle Monty | last post by:
Hi, I'm trying to create a program where the user can enter check information and the information is saved to a sequential access file. I'm getting an error when I run the program. The error is "Object reference not set to an instance of an object" and I'm getting it on the line that I have the ***** in front of below. Can anyone help me figure out how to fix this error? Thanks for your help. Here's my code: Option Explicit On Option...
3
1429
by: Zabooster | last post by:
I have a project to submit in a few hours' time. In order to explain what I need clearly, I will provide a very simple example. Suppose I have an application consisting of 3 forms- The first has a textbox(txtName) and a button leading to the second form. The second has another textbox(txtFamilyName) and a button both leading to the third form and sending the info to a row in MS Access. The third only has a button coming back to form1 so that...
0
9933
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9779
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11114
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10835
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9563
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7960
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5982
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3230
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.