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.
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.
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With