473,385 Members | 1,356 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,385 software developers and data experts.

Lock file

Can i lock a file in c#,
that i can move it and del it,
but other program don't have right to access(read) until i release it?

i read fileshare.none, but can't delete it without close the filestream or
streamwriter
there was still a cocurrency problem if i close the stream and delete it
just after close
what can i do?
Aug 26 '08 #1
2 4202
On Tue, 26 Aug 2008 03:21:20 -0700, macneed <ma*****@yahoo.com.hkwrote:
Can i lock a file in c#,
that i can move it and del it,
but other program don't have right to access(read) until i release it?

i read fileshare.none, but can't delete it without close the filestream
or
streamwriter
there was still a cocurrency problem if i close the stream and delete it
just after close
what can i do?
As far as I know, nothing. The file API just doesn't work that way. You
can assert exclusive access only while you have the file open, and you can
move or delete the file only while the file _isn't_ open.

If you want your application to have exclusive move and delete rights for
the file, you need to do that at the file security attributes level. Your
application would have to run as a user that is exclusively granted those
rights in the file's access control list.

Pete
Aug 26 '08 #2
On Aug 26, 2:21*pm, "macneed" <macn...@yahoo.com.hkwrote:
Can i lock a file in c#,
that i can move it and del it,
but other program don't have right to access(read) until i release it?

i read fileshare.none, but can't delete it without close the filestream or
streamwriter
there was still a cocurrency problem if i close the stream and delete it
just after close
what can i do?
I don't see why you'd want to forbid other processes from deleting
your file while you're working with it. Deletion will not delete the
actual data for as long as the file remains open - so, if another
process requests to delete the file, it will become invisible, but
your program can finish doing whatever it was doing with it. When you
close your file handle, the file will be physically deleted.
Aug 26 '08 #3

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

Similar topics

14
by: Antoon Pardon | last post by:
The queue and condition class allow threads to wait only a limited time. However this currently is implemented by a polling loop. Now for those who like to avoid polling I have here a Tlock...
0
by: John | last post by:
I've got multiple threads and processes that write to same file. Before writing all threads / processes first lock part of file and then write to file. If one thread / process locks file, another...
7
by: John Bailo | last post by:
I'm seeing some odd locking behavior when using an DB2400 database and running an ado.net transaction. My code -- in simplified form, appears at the bottom. I want to run several INSERT...
0
by: John Bailo | last post by:
I'm seeing some odd locking behavior when using an DB2400 database and running an ado.net transaction. My code -- in simplified form, appears at the bottom. I want to run several INSERT...
0
by: Andrew Dowding | last post by:
Hi Everybody, I have been looking at problems with my Windows Forms C# application and it's little Jet 4 (Access) database for the last few days. The Windows Forms app implements a facade and...
14
by: Gary Nelson | last post by:
Anyone have any idea why this code does not work? FileOpen(1, "c:\JUNK\MYTEST.TXT", OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.Shared) Dim X As Integer For X = 1 To 26 FilePut(1, Chr(X +...
4
by: muttu2244 | last post by:
hi all am trying to write some information into the file, which is located in ftp, and this file can be updated by number of people, but if at all i download a file from the ftp to my local...
12
by: Elmo Mäntynen | last post by:
Is there something better than using fnctl? It seems a bit intimidating with a quick look.
5
by: pgdown | last post by:
Hi, I have several processes accessing files from one folder, but only one process should ever access each file. Once one process has the file, no other process should be allowed to access it,...
2
by: WingSiu | last post by:
I am writing a Logging util for my ASP.NET application. I am facing mulit process problem. I developed a class LogFactory, and have a method called Get_Logger to create a FileLogger, which will...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.