Solved

Strring Split and  FileSystemEventArgs Issue

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

615 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