다음을 통해 공유


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

  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();
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)