Select Page

One of the most useful tools in a SharePoint developers arsenal is Reflector. Just in case you haven’t heard or used it before here’s the link: http://www.red-gate.com/products/reflector/index.htm. While it’s great to see the raw code behind SharePoint there is the occasional moment where the use of a resource string hinders understanding.

By default the StringResourceManager generated from the VS RESX generator is marked internal. Therefore it is very common to find no easy way to access the raw string value.

The following code snippet is something I employ to resolve this issue. It employs reflection to get around the ‘internal’ nature of the code.

Assembly assembly = Assembly.LoadFile(@”C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.Office.Server.Search.dll”);

           Type resourceType = assembly.GetType(“Microsoft.SharePoint.Portal.WebControls.StringResourceManager”);

           string piValue = (string)resourceType.InvokeMember(“GetString”,
               BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public,
               null, null, new object[] { Microsoft.SharePoint.Portal.WebControls.LocStringId.NewsFeed_TimeNow_Text });

It simply creates the string resource object and invokes the GetString member with the Identifier.