views:

31

answers:

2

Using the SPSite contructor (new SPSite(mySiteId)) returns a cached entry, even though site no longer exists. How can I prevent this?

A: 

While I do not know the Sharepoint details, I can tell you calling new will NEVER return a cached object. It will ALWAYS be a newly allocated object, although the internals may point to cached objects.

leppie
I delete the SPSite instance with a certain ID, and then I try to get the same instance using the constructor. Until I recycle the application pool I get a non-null object.
iulianchira
So what does the SP docs say about the behaviour of deleted sites?
leppie
Well, let's just say that the SharePoint doc is not really thorough.
iulianchira
+1  A: 

We had the same problem and haven't found a solution for it yet. We tried to check whether a SPSite exists or not by calling the static SPSite.Exists(..) method. The method returned true also for sites that didn't exist any more.

But we have found a little workaround. We try to provoke a FileNotFoundException by calling the SPSite's Usage property. When the exception arise we know that the site doesn't exist any more.

After catching the exception you can call again the SPSite.Exists() method which will now return false.

Flo