473,763 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check for ReadOnly File is in Use

All,
I am working on one product where we need to check for physical file
is in use (if it is open by other application). What I found out is that I
am able to trap for those files whose attribute is not Set as ReadOnly. I
have done this by opening file using FileStream Object opening in Edit mode
with No Shared. But if I am try to apply same logic for ReadOnly files, then
it throws NonAuthorized exception. This exception is also raised even when I
try to open this file even if this is not in use by other application.

Any suggestion would be helpful

Thanks
Mayur Chauhan
Jun 27 '08 #1
3 4110
J T

Here is the code : you can check FileAttribute

Imports System.IO

Dim Filepath as string = "c:\\myFile.txt "

If (File.GetAttrib utes(Filepath)) Then
If (FileAttributes .ReadOnly = FileAttributes. ReadOnly) Then
MsgBox("File is read only")
End If
End If
Jun 27 '08 #2
Here is the code : You can use FileAttributes to do this

Imports System.IO
Dim Filepath as string = "c:\\myFile.txt "
If (File.GetAttrib utes(Filepath)) Then
If (FileAttributes .ReadOnly = FileAttributes. ReadOnly) Then
MsgBox("File is readd only")
End If
End If

"Mayur H Chauhan" wrote:
All,
I am working on one product where we need to check for physical file
is in use (if it is open by other application). What I found out is that I
am able to trap for those files whose attribute is not Set as ReadOnly. I
have done this by opening file using FileStream Object opening in Edit mode
with No Shared. But if I am try to apply same logic for ReadOnly files, then
it throws NonAuthorized exception. This exception is also raised even when I
try to open this file even if this is not in use by other application.

Any suggestion would be helpful

Thanks
Mayur Chauhan
Jun 27 '08 #3
Thanks for you reply.
But here what I want to know is whether ReadOnly file is currently Open or
not. In Other words, Whether ReadOnly file is currently used by any other
application.
--
Thanks and Regards,
Mayur H Chauhan

Software Developer
www.myarcane.com
"JT" <JT@discussions .microsoft.comw rote in message
news:E0******** *************** ***********@mic rosoft.com...
Here is the code : You can use FileAttributes to do this

Imports System.IO
Dim Filepath as string = "c:\\myFile.txt "
If (File.GetAttrib utes(Filepath)) Then
If (FileAttributes .ReadOnly = FileAttributes. ReadOnly) Then
MsgBox("File is readd only")
End If
End If

"Mayur H Chauhan" wrote:
>All,
I am working on one product where we need to check for physical
file
is in use (if it is open by other application). What I found out is that
I
am able to trap for those files whose attribute is not Set as ReadOnly. I
have done this by opening file using FileStream Object opening in Edit
mode
with No Shared. But if I am try to apply same logic for ReadOnly files,
then
it throws NonAuthorized exception. This exception is also raised even
when I
try to open this file even if this is not in use by other application.

Any suggestion would be helpful

Thanks
Mayur Chauhan

Jun 27 '08 #4

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

Similar topics

15
6985
by: Dan S | last post by:
My application asks the user to enter in a date - in the mm/dd/yyyy format. Is there any quick and easy way to verify the date the user enters is formatted correctly? Right now I'm calling DateTime.Parse() and catching the FormatException but it seems this is a bit inefficient - catching the exception that is. There is some pretty obvious delay while it traces back up the call stack. Is there a better way? Something that returns a bool...
4
12289
by: Pete Kane | last post by:
Hello all, how can I check for multiple file attributes using bitwise operators ? I'm thinking along the lines of string fname = "c:\\test.txt"; if(File.GetAttributes(fname) & (FileAttributes.ReadOnly | FileAttributes.Archive )) {
2
1361
by: Raed Sawalha | last post by:
I'm reading XML files using XmlDocument, in some cases i have XML marked with readonly, so when tried to write to them an Access Denied exception is generated, is there a way to change the XML file state in order to successfully write to it. or there are other ways to write to xml though it is readonly? regards
1
4237
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get the example to work. I created the following two classes, provided with the example: *-*-**-*-*-*-*-*-*-*-*-*-**-*-*-*-*-CheckBoxColumn Class:-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-**-*-*-*
2
11164
by: Suma | last post by:
Hi To open a notepad file, right now I am using Process.start. But this does not ensure that the file is opened in readonly mode How can I make a notepad file open in Readonly mode I do not want to change its attributes to Readonly I do not want to open it in browser or in any other editor except notepad I do not want to use MFCAppWizard of VC++ or VB to create my own editor. I do not want to paste the text in some richtextbox...
2
7528
by: Ron | last post by:
Hello, the following sub (below) reads an excel file to a webpage using BinaryReader. If anyone tries to modify the excel file from the browser this places the excel file in ReadOnly mode, and no one can then touch the file, I can't delete it, etc. The file will still display on the browser. The only way I have been able to release the file from ReadOnly mode is to reboot the server computer. Obviously, I can't keep doing that. ...
1
1545
by: Erik Fjelldal | last post by:
How can I check if a file is in use, I have file and I want to know if someone have the file opened for writing, I dont care if they have opened the file readonly. The type of file can be all types. Erik Fjelldal
4
4621
by: ghjk | last post by:
I have check boxes in my php page. when I click som check boxes and click submit button I want to set read only to check boxes values. This is my code. But it is not working. <td><input value="1" type="checkbox" id="1" name="check"/>test1</td> <td ><input value="2" type="checkbox" id="2" name="check"/>test2</td> <td ><input value="3" type="checkbox" id="3" name="check"/>test3</td> document.getElementByNamme('check').readOnly='readonly';...
3
2616
by: ghjk | last post by:
I want to set read only for check box when I click submit button. But my code didn't work. This is my code java script code. document.getElementsById('check').disabled=true; document.getElementsById('check').disabled=true; or document.getElementById('check').readOnly=true; document.getElementById('check').readOnly=true; could someone help me? I'm using php and javascript.
0
9566
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
9389
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
10149
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...
0
10003
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9943
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,...
1
7370
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
5271
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3529
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2797
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.