|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionWhile doing some files-related operations like renaming, moving or deleting, many of you might encounter this kind of message:
This is the standard way Windows Explorer notifies the user that some file is in use, and therefore it cannot be “changed” in any way (that is renamed, moved, deleted, etc.) Of course there is the way for an application to notify Windows Explorer about which files are in use. For example Microsoft Office applications do that. When Windows Explorer is notified, the message saying that the file is in use looks different:
This article explains how to write an application which notifies Windows Explorer about used files. How to do it?The easiest way for a developer is to implement a COM interface named
If everything was OK, Windows Explorer shows a message box (like the second one from this article) with the name of the application. Using the codeI have created a // GUID, which must be unique, used to register an application in the registry
[assembly: Guid("{abcdef12-ca3b-a654-e640-bf50b3aba521}")]
// Application title which will be shown by the Windows Explorer
[assembly: AssemblyTitle("FileLockerApplication")]
...
// registers the application in the registry
FileLocker.Register();
string path = "some_file.txt";
// creates or opens the file and locks it
using (FileStream fs = File.Open(path, FileMode.OpenOrCreate,
FileAccess.ReadWrite, FileShare.None))
// notifies Windows Explorer that the file is in use
using (FileLocker fl = new FileLocker(path))
{
// here might be some code
}
// deletes the file
File.Delete(path);
// unregisters the application from the registry
FileLocker.Unregister();
The appropriate keys in the registry are created by the FileLocker class membersStatic methods
Constructors and instance methods
History
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||