HPFE455
asked on
Strring Split and FileSystemEventArgs Issue
The input path is C:/Users/guest/Desktop/Fox
After passing this to the function onDeleted, the path become
C:/\Users/guest/Desktop/Fo x.
I tried using Path also, but I couln't find any solution. Please help me.
After passing this to the function onDeleted, the path become
C:/\Users/guest/Desktop/Fo
I tried using Path also, but I couln't find any solution. Please help me.
List<string> item = new List<string>();
private void OnElapsedTimer(object source, ElapsedEventArgs e)
{
for (int index = 0; index < timerItems_.Count; index++)
{
path = item[index]; // value : C:/Users/guest/Desktop/Fox
if (!Directory.Exists(path))
{
string drive, folder;
drive = path.Substring(0, 2); //value is : C:/
folder = path.Substring(3); //Value is: Users/guest/Desktop/Fox
var fseArgs = new FileSystemEventArgs(WatcherChangeTypes.Deleted, @drive, @folder);
onDeleted(path, fseArgs);
}
}
}
void onDeleted(object source, FileSystemEventArgs e);
{
// Here e.FullPath is C: /\Users/guest/Desktop/Fox
// Expected Path : C:/Users/guest/Desktop/Fox
}
May I inquire as to why you are using FileSystemEventArgs in the first place? It's not that you can't, but that class is intended to be used as an argument to an event handler related to a FileSystemWatcher. Did you inherit the FileSystemWatcher in your own derived class?
ASKER
No, I didn't inherit, just added the below code trying to Pass to FileSsystemWatcher OnDelete method just for special cases.
var fseArgs = new FileSystemEventArgs(Watche rChangeTyp es.Deleted , @drive,@folder);
My application will watch all file events, in additionally I need to check if the user deletes the Filewatcher folder itself, then send a similar delete events. And I am using the same FileSystemWatcher OnDelete function in my code above.
I have written a sample console application that works as expected. But in my actual application, the path become wrongly formatted.
var fseArgs = new FileSystemEventArgs(Watche
My application will watch all file events, in additionally I need to check if the user deletes the Filewatcher folder itself, then send a similar delete events. And I am using the same FileSystemWatcher OnDelete function in my code above.
I have written a sample console application that works as expected. But in my actual application, the path become wrongly formatted.
I guess that's where I am confused, because as your code is posted it looks as though OnDelete is a part or your class. You wouldn't have access to FileSystemWatcher's OnDelete method because it is a protected method--unless you inherited the class, hence my question.
The directory separator character in Windows is actually backslash ( \ ). Is there any reason you are using forward slashes ( / )?
The directory separator character in Windows is actually backslash ( \ ). Is there any reason you are using forward slashes ( / )?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i have resolved the issue by changing the implementation in our project