Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / IDE / May 2004

Tip: Looking for answers? Try searching our database.

Iterating project files seems very slow...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew Hilton - 30 Apr 2004 05:56 GMT
Hello,

We have a lot of files in different directories in our project.  I wrote a
macro to find and open a source file based on the filename rather than using
the solution explorer.  But it's so slow as to be unusable. Is there
something obvious in my code, or is there another way to do this?

Andrew

Public Sub FindFile()

   Dim ps As ProjectItems =
ActiveDocument.ProjectItem.ContainingProject.ProjectItems

   Dim s As String = InputBox("Enter part of the filename to open.", "Open
File")

   Dim re As New Regex(s, RegexOptions.IgnoreCase)

   If s = "" Then Exit Sub

   If Not IterateProjectItems(ps, re, s) Then MsgBox("No matching files
found")

End Sub

Private Function IterateProjectItems(ByRef ps As ProjectItems, ByRef re As
Regex, ByVal s As String)

   Dim pi As ProjectItem

   Dim found As Boolean

   For Each pi In ps

       If re.IsMatch(pi.Name) Then

           found = True

           pi.Open()

           pi.Document.Activate()

       End If

       found = IterateProjectItems(pi.ProjectItems, re, s) Or found

   Next

   IterateProjectItems = found

End Function
Carlos J. Quintero [MVP] - 04 May 2004 11:16 GMT
Basically your code is right expect a couple of details not related to
performance:

1)    Dim ps As ProjectItems =
ActiveDocument.ProjectItem.ContainingProject.ProjectItems

This will cause exception if there is no document open.

2) pi.Open()
   pi.Document.Activate()

Maybe not all ProjectIems has a Document, so this statement can fail too.
Use instead:

Dim objWindow As Window

objWindow = pi.Open()
objWindow.Visible = True

About performance, if you move the code from a macro into a compiled addin,
it should fly faster.

Signature

Carlos J. Quintero (Visual Developer - .NET MVP)

FAQs, Knowledge Base, Files, Docs, Articles, Utilities, etc. for .NET
addins:
http://groups.yahoo.com/group/vsnetaddin/ (free join)

> Hello,
>
[quoted text clipped - 48 lines]
>
> End Function
Andrew Hilton - 10 May 2004 05:13 GMT
Carlos,

Thank you for your tips. A compiled add-in makes a lot more sense. After
some thought here we realised the same thing could be achieved by opening
the project file into a xml dom and searching for the files using xpath
(although I have yet to do any xml processing using .net). That would be a
lot quicker and still achieveable within the macro environment. If I ever
get around to coding it - I will post it here. Forgot to mention we're using
vsnet 2001, maybe macro performance has improved in the latest version.

Andrew

> Basically your code is right expect a couple of details not related to
> performance:
[quoted text clipped - 72 lines]
> >
> > End Function

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.