Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting if I'm running in SharePoint

Is there a way for my ASP.net Application to know if it's running within SharePoint (2010), but without referencing SharePoint Assemblies? (So I can't just check if SPContext.Current is null).

I wonder if it's viable to get all Assemblies that are loaded by name? So if I see that my AppDomain contains a Microsoft.SharePoint assembly then I know I'm in SharePoint.

Use case: The Assembly runs outside of SharePoint as well, but referencing SharePoint DLLs requires to deploy them (not possibly due to licensing) or getting Exceptions when I access a SharePoint method.

At the moment I use conditional compilation, but I'd like to get away from that and use a DI-mechanism to choose one of two classes, depending if I'm in SharePoint.

like image 940
Michael Stum Avatar asked Jun 03 '11 20:06

Michael Stum


People also ask

Can you track activity on SharePoint?

You can view the activities in the SharePoint report by choosing the Activity tab. Select Choose columns to add or remove columns from the report. You can also export the report data into an Excel . csv file by selecting the Export link.


2 Answers

bool isSharepoint =
     AppDomain
        .CurrentDomain
        .GetAssemblies()
        .Any(a => new AssemblyName(a.FullName).Name == "Microsoft.SharePoint");

Untested, but this would perform the check for a loaded assemblies whose name was Microsoft.SharePoint.

like image 161
Guvante Avatar answered Sep 21 '22 00:09

Guvante


One way wold be to check the command line parameters of your current process (w3wp.exe) and look for the "-ap "SharePoint Content AppPool". Personally, I prefer the method you mentioned (looking for Microsoft.SharePoint.dll assembly).

like image 29
Nemanja Trifunovic Avatar answered Sep 21 '22 00:09

Nemanja Trifunovic