Link to home
Start Free TrialLog in
Avatar of HPFE455
HPFE455Flag for United States of America

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/Fox.    
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


}

Open in new window

Avatar of kaufmed
kaufmed
Flag of United States of America image

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?
Avatar of HPFE455

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(WatcherChangeTypes.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.
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 ( / )?
ASKER CERTIFIED SOLUTION
Avatar of HPFE455
HPFE455
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HPFE455

ASKER

i have resolved the issue by changing the implementation in our project