Click here to Skip to main content
Sign Up to vote bad
good
Hello,
 
I want to write an application able to find text in files and report result back in a graphical way (to show files relationship).
 
I would like to hear some recommendations on what tech I can use to achieve this. My first attempt was to write a Visual Studio Isolated Shell because I would like to use its FindInFiles command. So I can pass in the command line the directory to look into and the text to look up.
 
I'm more of a C++ programmer, but I thought about using C# and .NET since the language can be easier to program with if I want to use any .NET shape drawing library/controls available.
 
Is it possible to use VS 2012's FindInFiles command programmatically in a stand-alone application? Or alternatively, what do you recommend I should be looking at? I have seen things like EnvEDT.
 
Many thanks!
Posted 23-Jan-13 8:31am


1 solution

It's easy. You need to do it by yourself.
 
You need to use: System.IO.Directory.GetFiles, http://msdn.microsoft.com/en-us/library/system.io.directory.getfiles.aspx[^].
 
There is one unpleasant problem with this API. To take it into account, please see this discussion: Directory.Get.Files search pattern problem[^].
 
The rest of search is on yours: you need to open each file, read it and perform the search in it contents. It depends of file formats and your criteria.
 
If you want to do it with UI and show results as they appear, it will take some considerable work. First of all, you will need to do all the search is a separate thread. Then, you will need to have a control as a sink of search result (I would suggest some ListBox). But how to put found data on UI as they appear? This is a bit harder to do.
 
You cannot call anything related to UI from non-UI thread. Instead, you need to use the method Invoke or BeginInvoke of System.Windows.Threading.Dispatcher (for both Forms or WPF) or System.Windows.Forms.Control (Forms only).
 
You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].
 
See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].
 
—SA
  Permalink  
Comments
Espen Harlinn - 23-Jan-13 19:39pm
5'ed!
Sergey Alexandrovich Kryukov - 23-Jan-13 19:47pm
Thank you, Espen. —SA
berilium - 8-Feb-13 18:24pm
Thanks Sergey!
Sergey Alexandrovich Kryukov - 8-Feb-13 18:29pm
You are very welcome. Good luck, call again. —SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Christian Graus 488
1 Ron Beyer 306
2 Tadit Dash 253
3 samadhan_kshirsagar 229
4 OriginalGriff 198
0 Sergey Alexandrovich Kryukov 7,041
1 Prasad_Kulkarni 3,815
2 OriginalGriff 3,557
3 _Amy 3,372
4 CPallini 3,034


Advertise | Privacy | Mobile
Web01 | 2.6.130619.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid