2

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.

3 Answers 3

2

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.

1
  • 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
    Commented Mar 15, 2012 at 14:52
0

You could try using System.Reflection:

Assembly.GetExecutingAssembly().GetName().Version

Ian.

1
  • 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
    Commented Mar 15, 2012 at 9:15
0

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();
1
  • 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
    Commented Mar 15, 2012 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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