Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / January 2006

Tip: Looking for answers? Try searching our database.

why can i copy a locked file, but not read it.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tim_Mac - 28 Jan 2006 23:33 GMT
hi,
i need to read a file that is already opened exclusively by another
process.  yes this seems like a contradiction, but i can always do
File.Copy on that file, regardless of how 'locked' it is.  and yet i
cannot use File.Open() with FileAccess.Read.
this behaviour is widely reported on the newsgroups regarding .Net 1.1,
but it seems to be the same in .net 2.0.  i have not found any
explanations of it.  surely File.Copy internally must open a file
stream on the locked file and just stream the bytes out to the
destination file, so i'm baffled as to what the difference is with
File.Open(...read...)

windows behaves the same way with locked files.  if there is a file you
cannot open, you can still copy it.  i need to do this in .net.  volume
shadow copy is not an option.  also, i don't want to use File.Copy to a
temp location, then read it, and then delete it.  that is just plain
wrong.

this is the code i'm using:
FileStream stream = File.Open(filename, FileMode.Open,
FileAccess.Read);

does anyone have ideas?
thanks
tim
Willy Denoyette [MVP] - 28 Jan 2006 23:59 GMT
| hi,
| i need to read a file that is already opened exclusively by another
[quoted text clipped - 21 lines]
| thanks
| tim

You are trying to open the file in non shared mode, this isn't possible if
the file is already open right?

Use the File.Open overload that takes four arguments and specify
FileShare.ReadWrite as sharing mode.

Willy.
Tim_Mac - 29 Jan 2006 09:45 GMT
hi willy, you're right!  that does it.  i always thought that the
FileShare options only affected other processes opening the file after
i had opened it, not existing file-sharing conditions.
that's a great help, thank you so much.
tim

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.