Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 9:31am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 at 23-Jan-13 19:39pm
   
5'ed!
Sergey Alexandrovich Kryukov at 23-Jan-13 19:47pm
   
Thank you, Espen.
—SA
berilium at 8-Feb-13 18:24pm
   
Thanks Sergey!
Sergey Alexandrovich Kryukov at 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
0 OriginalGriff 274
1 Sergey Alexandrovich Kryukov 255
2 Shweta N Mishra 216
3 PIEBALDconsult 200
4 BillWoodruff 174
0 OriginalGriff 7,630
1 Sergey Alexandrovich Kryukov 7,022
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,525


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100