Getting GAC Path Using Reflection
Recently I was working on a SharePoint timer job for some data synchronization across numerous WebParts. In order to do this I had to load through code the pertinent assemblies from the GAC (I know, I know. I should be using the bin for security purposes, but it is a client request to be in this form) so that I could get access to the various types dynamically.
I found an assortment of sundry techniques that people shared, however I didn’t really dig the sum of string literals that they were using to do it. I am finding that using reflection is much more efficient and clean, so I thought I would post the code snippet for others consumption:
-
private static string GacPath()
-
{
-
PropertyInfo pi = typeof (Environment).GetProperty("GacPath", BindingFlags.Static | BindingFlags.NonPublic);
-
if (pi == null)
-
{
-
return null;
-
}
-
MethodInfo mi = pi.GetGetMethod(true);
-
return (string) mi.Invoke(null, null);
-
}
Related posts:
- Returing Virtual Directory Path From Web Application
- ToolPart Class With System.Reflection
- Stupid SharePoint Delimiters
- Getting a SharePoint Field Value In C#
- Get Locale From SPWeb URL
No Comments »
No comments yet.
RSS feed for comments on this post. TrackBack URL























Articles & Research
SharePoint Architecture
Research Methodology
Personal/Off-Topic
Article Or Research Filed Under 
