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 building an application that interacts with SharePoint 2010. It is a Silverlight application built on the Managed Client Object Model.

The application is set up on SharePoint like this: User takes the .XAP file and uploads it to some SharePoint document library. Next, he or she adds a new Silverlight web part to some page and directs that web part to use the .XAP file. Once that is done and the page is opened, the Silverlight application is loaded and ready to run.

As we all know, SharePoint Managed Client Object model cannot interact with SharePoint 2007. I need to be able to handle the scenario in which the user mistakenly sets up the application on a SharePoint 2007 page. I want my application to realize that it is supposed to work with the wrong version of SharePoint and to throw an Exception.

How can I determine the SharePoint version using the Managed Client Object Model? Thanks.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Your code will throw an exception when trying to instantiate a Managed Client Object Model Site object, just catch that and handle appropriately.

share|improve this answer
    
Thanks! Your explanation solves my trouble. –  Boris Nov 18 '11 at 13:37

You do not need write something to throw an exception, Your application will throw the exception anyway if it is not hosted on SP2010 :)

If you want your application to stop gracefully , You can write some code (like below)in *Application_Startup* handler in the Silverlight Application

private void Application_Startup(object sender, StartupEventArgs e)
   {

       // Code To detect something on the application starts up

       using (ClientContext ctx = new ClientContext("http://sp2010site"))
       {
           try
           {
               ctx.Web.Title;
           }
           catch (PropertyOrFieldNotInitializedException x)
           {
               // Present message to User and turn off the screens\tabs  
           }

       }
   }
share|improve this answer
    
Thank you for your reply. I think it is arguable if the code you have provided is the best example to handle the Managed Client Object Model compatibility. –  Boris Nov 18 '11 at 13:39
    
May not be the best but a valid one. By the way, please share if you find the best :) –  Amit Kumawat Nov 18 '11 at 13:41
    
I agree with you completely. I'll share my own code regarding this issue, once I implement and test it. Cheers. –  Boris Nov 18 '11 at 13:53

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.