Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Strring Split and  FileSystemEventArgs Issue

Posted on 2012-03-30
5
Medium Priority
?
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37789120
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
ID: 37789150
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 75

Expert Comment

by:käµfm³d 👽
ID: 37789227
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
ID: 37789355
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
ID: 37850319
i have resolved the issue by changing the implementation in our project
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

719 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