Home > General > Determining the NameSpace for an ECT in SharePoint WP

Determining the NameSpace for an ECT in SharePoint WP

So the other day, while working on a SharePoint project, I started writing a custom workflow in Visual Studio and I needed to access an ECT programmatically. To date in this project all my WebParts had the usual custom properties to define the NameSpace for the ECT that I needed to access. But suddenly I was in a situation where that information was not available.

So I had to try and find it a different way. After sitting in a debugging session for a bit and interrogating objects and properties, I eventually found it. So in the interest of sharing some code, here it is. Now I couldn’t find a solution online after googling & binging for a bit. And there might be other solutions out there much better than mine.

using (new SPServiceContextScope(SPServiceContext.GetContext(SPContext.Current.Site)))
{
 var service = Microsoft.SharePoint.Administration.SPFarm.Local.Services.GetValue<BdcService>(String.Empty);
 Microsoft.BusinessData.MetadataModel.IMetadataCatalog catalog = service.GetDatabaseBackedMetadataCatalog(SPServiceContext.Current);

 var tmp = catalog.GetEntities(“Agencies”);
 var _NameSpace = tmp[0].Key;
}

Now the “Agencies” entity is just an ECT that I know will be there and it is purely used to be able to extract the NameSpace. And there you have it, no more custom properties on my WebParts to configure the NameSpaces for the ECTs.

Advertisements
  1. Kevin
    June 5, 2014 at 07:25

    Sorry mate… Not much to add to this string… It’s all “geek speak”.. I did pick up a new term however… “Binging”… Thanks for that I will try to find a place in my vocabulary to use it!

  2. Sheromi Singh
    June 11, 2014 at 16:26

    Thank henry this is really helpful

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: