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

I am writing a console application for SharePoint. Mostly, I will be using it for both MOSS and SharePoint 2010. I have two separate functions - one for MOSS and other for SharePoint 2010. In my Main method, I want to detect the version of sharepoint and call the funtion accordingly.

Please let me know the best way to do that.

share|improve this question
    
Have you tried looking in this stackoverflow.com/questions/2205148/… –  Daniel Ziga Dec 12 '11 at 10:20
    
Another one - stackoverflow.com/questions/2309728/… –  Nitin Rastogi Dec 12 '11 at 10:24
    
@NitinRastogi, I need it for console application, so this don't work –  SP.NET Dec 12 '11 at 10:29
    
Try this - SPFarm.Local.BuildVersion; –  Nitin Rastogi Dec 12 '11 at 10:37

3 Answers 3

up vote 1 down vote accepted

Are you calling the SharePoint server API from within your console application? If so, I'm not sure this will work as you would need to reference and build your app against both the 2007 and 2010 version of the SharePoint.dlls. Visual Studio won't like that (unless you build against the 2007 version to run to the 2010 version)

share|improve this answer
    
You are correct! Any idea how to do it then? –  SP.NET Dec 13 '11 at 9:26
    
Depends on what you are doing inside the console application. You might find that creating a powershell script instead of a console app is a better option. –  Paul Lucas Dec 14 '11 at 21:23

SPFarm.BuildVersion works with both 2007 and 2010.

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spfarm.buildversion.aspx

share|improve this answer
    
This will not work in my situation. See answer by Paul Lucas. –  SP.NET Dec 13 '11 at 13:03

If you want to check which UI the SharePoint site is having, I would recommend to use SPWeb.UIVersion property of the current site. A value of 3 means it has the SharePoint 2007 interface and a value of 4 means that it has the latest SharePoint 2010 Interface.

share|improve this answer
    
Just a possible workaround, if you think so. Can you have multiple console applications, the primary one just to identify the SharePoint version? I have found a post which could be helpful. sharing-the-experience.blogspot.com/2011/05/… –  Deepu Nair Dec 13 '11 at 17:36

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.