Code Snippet: Get the FileBackedMetadataCatalog on the Server or Client
Applies to: SharePoint Server 2010
In this article
Description
Prerequisites
To use this example
Description
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.
Prerequisites
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.
To use this example
Start Visual Studio, and then create a new C# Console application project. Select .NET Framework 3.5 when you create the project.
From the View menu, select Property Pages to bring up the project properties.
On the Build tab, for the Platform target, select Any CPU.
Close the project properties window.
In Solution Explorer, under References, remove all project references except for System and System.Core.
Add the following references to the project:
Microsoft.BusinessData (from SharePoint_RootFolder\ISAPI)
Microsoft.SharePoint
Replace the auto-generated code in Program.cs with the code listed at the end of this procedure.
Replace entityFilePath with a valid value.
Save the project.
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();
catalog.ImportPackage(
reader,
parseContext,
BDCParser.PackageContents.Model
| BDCParser.PackageContents.Properties
| BDCParser.PackageContents.LocalizedNames
| BDCParser.PackageContents.Permissions);
if (parseContext.Errors.Length > 0)
{
//Print errors.
}
See Also
Reference
ParseContext
Microsoft.SharePoint.BusinessData.Parser.ParseContext
FileBackedMetadataCatalog
FileBackedMetadataCatalogImportPackage(XmlReader, ParseContext, PackageContents)
Microsoft.SharePoint.BusinessData.MetadataModel.FileBackedMetadataCatalog
FileBackedMetadataCatalog.ImportPackage(XmlReader, ParseContext, PackageContents)