The FileSystemWatcher class ignores the uppercase characters in a file name (873196)
The information in this article applies to:
- Microsoft Visual Studio .NET (2003), Professional Edition
- Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
- Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
- Microsoft Visual Studio .NET (2003), Academic Edition
- Microsoft Visual Studio .NET (2002), Professional Edition
- Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
- Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
- Microsoft Visual Studio .NET (2002), Academic Edition
SYMPTOMSIn Microsoft Visual Studio .NET, you may use the FileSystemWatcher class monitor changes that are made to the file system. When a file is changed, created, or deleted, the FileSystemWatcher class returns the name of the file in lowercase letters even if the actual file name contains uppercase letters.RESOLUTIONTo resolve this problem, use the System.IO.Directory class to retrieve the actual file name. To do this, follow these steps: - Locate the following code in the Form1.vb file:
Microsoft Visual Basic .NET code' Define the event handlers.
Private Shared Sub OnCreate(ByVal source As Object, ByVal e As FileSystemEventArgs)
' Specify what task is performed when a file is changed, created, or deleted.
MessageBox.Show("The file '" & e.FullPath & "' is created")
End Sub Microsoft Visual C# .NET code//Define the event handlers.
private static void OnChanged(object source, FileSystemEventArgs e)
{
//Displays a message when a file is created.
MessageBox.Show("The file '" + e.FullPath + "' is created");
}
- Replace the code that you located in step 1 with the following code:
Visual Basic .NET codePrivate Shared Sub OnCreate(ByVal source As Object, ByVal e As FileSystemEventArgs)
Dim ActualFileName As String() = Directory.GetFiles("C:\", e.Name)
Dim dir As String
For Each dir In ActualFileName
MessageBox.Show("The file '" & dir & "' is created")
Next
End Sub Visual C# .NET codeprivate static void OnChanged(object source, FileSystemEventArgs e)
{
string[] ActualFileName = Directory.GetFiles ("C:\\", e.Name);
foreach (string dir in ActualFileName)
{
MessageBox.Show("The file '" + dir + "' is created");
}
} - On the Build menu, click Build Solution.
- On the Debug menu, click Start.
- Create a text file that is named MYAPP1.txt, and then save the file on drive C.
- Close the file. You see a message box that contains the following message:
The file 'C:\MYAPP1.txt' is createdNotice that the name of the file in the message is displayed as MYAPP1.txt.
REFERENCESFor more information, visit the following Microsoft Developer Network (MSDN) Web sites:
Modification Type: | Major | Last Reviewed: | 7/21/2004 |
---|
Keywords: | kbFileSystems kbcode kbtshoot kbprb KB873196 kbAudDeveloper |
---|
|