Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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

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
 
Share this answer
 
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900