Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

There is a requirement to get the version number of another web part in a page to be displayed programmatically.

We get details of the web part including the version number in the web part gallery as seen below.

enter image description here

I need to display this detail into a web part if possible. It would be better to get another web part's information even without accessing the web part gallery objects, may be using the webpartmanager class to access the page and get the web part properties from it. Can anyone share some tips?

UPDATE: I dont want to get information on the Web part that I am deploying. I know that System.Assembly can help in getting the version number of any dll. But I would avoid that since all web parts are not deployed in the same place.

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

If I am understanding correctly, you want to know the version of an assembly, but you don't want to reflect on the assembly and you do not want to read the catalog that stores the information.

If my understanding of the requirments is correct, then the answer is you cannot.

The SPWebPartManager will return a collection of the web parts on the page. However, the type of those objects will be System.Web.UI.WebControls.WebParts.WebPart. You could test if it matches a known type that derives from WebPart (the "is" operator in c#), but in this scenario, you must know the type you are looking for.

However, if you do successfully get a reference to the assembly, the only way to determine the version of that assembly is to use the System.Reflection namespace. In your situation, the restrictions will prevent you from accomplishing the goal.

share|improve this answer
    
Thanks Paul for the detailed answer. I believe the same too. But wanted to check if there is something that I am missing. –  Deepu Nair Mar 15 '12 at 14:52
add comment

You could try using System.Reflection:

Assembly.GetExecutingAssembly().GetName().Version

Ian.

share|improve this answer
    
Thanks Ian. But, GetExecutingAssembly gets the Assembly that the current code is running from. I am looking for getting version of another web part and honestly I prefer to use SharePoint object model class instead of System.Assembly –  Deepu Nair Mar 15 '12 at 9:15
add comment

If you want to show the version of a custom web part you have developed, you can use reflection to get the version information like this:

System.Reflection.Assembly thisAssembly = this.GetType().Assembly;
string version = thisAssembly.GetName().Version.ToString();
share|improve this answer
    
Thanks Stig. I am looking for getting version of another web part and not the current web part that I am building and I prefer to use SharePoint object model class instead of System.Assembly –  Deepu Nair Mar 15 '12 at 9:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.