Code Snippet: Get the FileBackedMetadataCatalog on the Server or Client

SharePoint 2010

Last modified: May 05, 2010

Applies to: SharePoint Server 2010

In this article
To use this example

The following code example shows how to get the FileBackedMetadataCatalog on the server by using the Business Data Connectivity (BDC) service Runtime object model on the server. Note that FileBackedMetadataCatalog is also available on the client.

  • Microsoft SharePoint Server 2010 or Microsoft SharePoint Foundation 2010 installed on the server.

  • Microsoft .NET Framework 3.5 and Microsoft Visual Studio on the client computer.

  • At least one external content type registered in the BDC Metadata Store.

  1. Start Visual Studio, and then create a new C# Console application project. Select .NET Framework 3.5 when you create the project.

  2. From the View menu, select Property Pages to bring up the project properties.

  3. On the Build tab, for the Platform target, select Any CPU.

  4. Close the project properties window.

  5. In Solution Explorer, under References, remove all project references except for System and System.Core.

  6. Add the following references to the project:

    1. Microsoft.BusinessData (from SharePoint_RootFolder\ISAPI)

    2. Microsoft.SharePoint

  7. Replace the auto-generated code in Program.cs with the code listed at the end of this procedure.

  8. Replace entityFilePath with a valid value.

  9. Save the project.

  10. Compile and run the project.

using Microsoft.BusinessData.MetadataModel;
using Microsoft.BusinessData.Runtime;
using Microsoft.SharePoint.BusinessData.MetadataModel;
using Microsoft.SharePoint;
using Microsoft.SharePoint.BusinessData.SharedService;
using BDCParser = Microsoft.SharePoint.BusinessData.Parser;

// If using on the client, use these instead of the server DLLs.
//using BDCParser = Microsoft.Office.BusinessData.Parser;
//using Microsoft.Office.BusinessData.MetadataModel;

//entityFilePath is the path where the BDC model is stored on a local computer.
XmlReader reader = XmlReader.Create(entityFilePath); 
BDCParser.ParseContext parseContext = new BDCParser.ParseContext();
FileBackedMetadataCatalog catalog = new FileBackedMetadataCatalog();
                     | BDCParser.PackageContents.Properties
                     | BDCParser.PackageContents.LocalizedNames
                     | BDCParser.PackageContents.Permissions);          

if (parseContext.Errors.Length > 0)
   //Print errors.