Click here to Skip to main content
13,588,673 members
Rate this:
Please Sign up or sign in to vote.
See more:

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

Rate this: bad
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,[^].

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[^],
Control events not firing after enable disable + multithreading[^].

Espen Harlinn 23-Jan-13 19:39pm
Sergey Alexandrovich Kryukov 23-Jan-13 19:47pm
Thank you, Espen.
berilium 8-Feb-13 18:24pm
Thanks Sergey!
You are very welcome.
Good luck, call again.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

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

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