Solved

Strring Split and  FileSystemEventArgs Issue

Posted on 2012-03-30
5
215 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 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Server Error 11 58
Why does my excel data start at B1 instead of A1. 9 80
VB: Convert 2 dates to specific format 24 48
What Does This C# Code Block Do? 5 24
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…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

16 Experts available now in Live!

Get 1:1 Help Now