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 / Extensibility / August 2005

Tip: Looking for answers? Try searching our database.

How to retrieve parent projectitem?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
manfred.mail@gmx.at - 11 Aug 2005 17:16 GMT
I want to calculate the virtual path of a file included in a visual
studio .net project. But unfortunately i'm only able to get the
physical pathname of the project item.
At the moment i recursivly search the project tree from top to bottom
until i find the projitem object. At the same time the path is
generated - but this is very slow for large projects.
Starting from the projectitem object, is there any possibility to go
upwards in the project tree until the project root is reached?

Thanks, Manfred
Paul Skelton - 13 Aug 2005 15:27 GMT
ProjectItem.ContainingProject

>I want to calculate the virtual path of a file included in a visual
> studio .net project. But unfortunately i'm only able to get the
[quoted text clipped - 6 lines]
>
> Thanks, Manfred
manfred.mail@gmx.at - 15 Aug 2005 17:11 GMT
Yeah, but since i need to construct the virtual path I'll need the
predecessor of a projectitem in the project tree.
Carlos J. Quintero [VB MVP] - 16 Aug 2005 10:35 GMT
Yes, given a ProjectItem, ProjectItem.Collection returns the ProjectItems
collection it belongs to (do not confuse with ProjectItem.ProjectItems,
which is the collection of children), and then ProjectItems.Parent returns
the object parent , which can be a Project (you are done) or a ProjectItem
(such a folder, or a file which depends on, etc.). In the later case you
enter in recursion, etc.

Signature

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

> Yeah, but since i need to construct the virtual path I'll need the
> predecessor of a projectitem in the project tree.
manfred.mail@gmx.at - 17 Aug 2005 16:16 GMT
Thanks for your help, but there is still a problem. As you mentioned,
ProjectItem.Collection returns the ProjectItems collection it belongs
to. But unfortunately this may not be the parent ProjectItem.

e.g. I need to calculate the virtual path to the selected project item
and therefore i retrieve my ProjectItems this way:

Dim proj as ProjectItem
Dim item As SelectedItem

For Each item In DTE.SelectedItems

   proj = item.ProjectItem
   ...

Next

I have tried this, but the proj.Collection.Parent points to the DTE
object, not to the predecessor of the current ProjectItem in the tree.

Best regards,
Manfred
Carlos J. Quintero [VB MVP] - 18 Aug 2005 09:39 GMT
Hummm, interesting. It could be because you are getting the ProjectItem from
the DTE.SelectedItems collection, because if you get it from the
Solution.Projects, Project.ProjectItems, etc. it should work fine. Not sure
it this will work, but you could try to retrieve a ProjectItem whose parents
are more meaningful using:

myProjectItem = DTE.Solution.FindProjectItem(item.ProjectItem.FileNames(0))'

That is, FindProjectItem retrieves a ProjectItem from the solution given its
file name. Hopefully its parents are correct this time.

Signature

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com

> Thanks for your help, but there is still a problem. As you mentioned,
> ProjectItem.Collection returns the ProjectItems collection it belongs
[quoted text clipped - 18 lines]
> Best regards,
> Manfred
manfred.mail@gmx.at - 19 Aug 2005 07:45 GMT
If've tested the code above but it seems that it doesn't work either
because when i retrieve my ProjectItem with the
Solution.FindProjectItem method, the myProjectItem.Collection property
is always nothing.

Best regards,
Manfred

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.