Solved

Strring Split and  FileSystemEventArgs Issue

Posted on 2012-03-30
5
213 Views
Last Modified: 2012-04-16
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

0
Comment
Question by:HPFE455
  • 3
  • 2
5 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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?
0
 

Author Comment

by:HPFE455
Comment Utility
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.
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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 ( / )?
0
 

Accepted Solution

by:
HPFE455 earned 0 total points
Comment Utility
Thanks  kaufmed,
 I tried both but alwyas getting a wrong slashes in the path.

I have resolved the issue by adding another method which will accept path as one of the parameter of type string .  (I think FileSystemEventArgs manipulation has some issue)

If user delete the watch directory, I used to call new method which will send a file delete evenet.

Th
0
 

Author Closing Comment

by:HPFE455
Comment Utility
i have resolved the issue by changing the implementation in our project
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now