Select to view content in your preferred language

How Do I Export Metadata

513
1
08-19-2022 01:44 PM
VidmasKondratas
Esri Contributor

I have an ArcGIS Pro web layer that's sourced to an ArcGIS Server URL (not Portal). How do I use the Pro SDK to export the metadata? I know how to do this with File Geodatabases and SDE connection files:

 

 

var gdbItem = ItemFactory.Instance.Create("K:\\connection_files\\ice_production.sde\\ice_production.ICE_OWNER.ARCTIC_WEEKLY");
IMetadata gdbMetadataItem = gdbItem as IMetadata;
gdbMetadataItem.SaveMetadataAsHTML(metadataFile.FullName, MDSaveAsHTMLOption.esriArcGISFull);

 

 

 And I know the web URL for the layer as a metadata link: https://server.esri.com/arcgis/rest/services/SIPAS/Arctic/FeatureServer/6/metadata

The metadata is a customer requirement for a data export from ArcGIS Pro as part of a larger ArcGIS Pro AddIn. I need to write this out to a file as HTML along with the exported data. I would like to use the ArcGIS Server as a source for the metadata instead of using a file path, but I can't seem to get it working or find examples on how to do it.

Tags (2)
0 Kudos
1 Reply
VidmasKondratas
Esri Contributor

As far as I can tell, you cannot use the Pro SDKs ItemFactory Create method with an ArcGIS Server URL (correct me if I'm wrong). But if you create the service with ArcGIS Pro 2.2+ and AGS 10.6.1+ you can use the URL I posted above to retrieve the metadata as HTML using the ArcGIS Server REST API in a Pro AddIn. I created a helper function to retrieve the HTML metadata and then wrote the string to an HTML file:

public async Task<string> GetMetadata(string baseUrl, string format, string output)
{
	var values = new Dictionary<string, string>
		{
			{ "format" , format },
			{ "output" , output }
		};
	var url = baseUrl + "/metadata";
	var content = new FormUrlEncodedContent(values);
	var response = await _httpClient.PostAsync(url, content);
	var responseString = await response.Content.ReadAsStringAsync();

	return responseString;
}

 

var metadata = await httpHelper.GetMetadata(baseUrl, "iso19139", "html");
if (File.Exists(metadataFile.FullName))
{
   File.Delete(metadataFile.FullName);
}
using (FileStream fileStream = metadataFile.Create())
{
   Byte[] text = new UTF8Encoding(true).GetBytes(metadata);
   fileStream.Write(text, 0, text.Length);
}

 https://developers.arcgis.com/rest/services-reference/enterprise/metadata.htm

0 Kudos