public void UpdateXMPData() { try { //ExStart:UpdateXMP // path to the modified file string filePath = "Images/Jpeg/sample.jpg"; // get xmp wrapper XmpPacketWrapper xmpWrapper = MetadataUtility.ExtractXmpPackage(filePath); // if wrapper is null if (xmpWrapper == null) { // create it xmpWrapper = new XmpPacketWrapper(); } // create package XmpPackage addingSchema = new XmpPackage("rs", "http://www.metadataworkinggroup.com/schemas/regions/"); // set date property addingSchema.AddValue("rs:createdDate", DateTime.UtcNow); // set string property addingSchema.AddValue("rs:File", "File name"); //initialze unordered xmp array XmpArray managersArray = new XmpArray(XmpArrayType.UNORDERED); managersArray.AddItem("Joe Doe"); managersArray.AddItem("Adam White"); // set array property addingSchema.SetArray("rs:managers", managersArray); // initialize xmp language alternative LangAlt availableDays = new LangAlt(); // add first value for 'en-us' language availableDays.AddLanguage("en-us", "Tue"); // add second value for 'en-us' languge availableDays.AddLanguage("en-us", "Fri"); // set LangAlt property addingSchema.SetLangAlt("rs:days", availableDays); // update xmp wrapper with new schema xmpWrapper.AddPackage(addingSchema); // create XmpMetadata with updated wrapper XmpMetadata xmpMetadata = new XmpMetadata(); xmpMetadata.XmpPacket = xmpWrapper; // update XMP MetadataUtility.UpdateMetadata(filePath, xmpMetadata); //ExEnd:UpdateXMP } catch (Exception exp) { } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { tabMetadataTypes.TabPages.Clear(); DataSet ds; using (StreamReader streamReader = new StreamReader(openFileDialog.FileName)) { try { ds = ExportFacade.ExportToDataSet(streamReader.BaseStream); } catch (GroupDocs.Metadata.Exceptions.InvalidFormatException) { MessageBox.Show(@"This format is not supported"); return; } catch (GroupDocs.Metadata.Exceptions.GroupDocsException ex) { MessageBox.Show(string.Format("Error: {0}", ex.Message)); return; } } propertiesEditor = null; saveMetadata.FileName = openFileDialog.FileName; if (ds.Tables.Count == 0) { MessageBox.Show(@"Metadata not found"); } else { for (int i = 0; i < ds.Tables.Count; i++) { DataTable table = ds.Tables[i]; Control child; string tabName; switch (table.TableName.ToLower()) { case "xmp": tabName = "XMP metadata"; XmpPacketWrapper xmpPacket = MetadataUtility.ExtractXmpPackage(openFileDialog.FileName); ucXmpTree xmpTree = new ucXmpTree(); xmpTree.LoadControl(xmpPacket); ResizeControl(xmpTree); child = xmpTree; break; case "pdf": case "doc": case "xls": case "ppt": tabName = "Document properties"; MetadataPropertyCollection properties = MetadataUtility.ExtractDocumentProperties(openFileDialog.FileName); propertiesEditor = new ucPropertiesEditor(); ResizeControl(propertiesEditor); propertiesEditor.LoadControl(properties); child = propertiesEditor; break; default: tabName = string.Format("{0} metadata", table.TableName); DataGridView gridView = new DataGridView(); ResizeControl(gridView); gridView.DataSource = table; child = gridView; break; } tabMetadataTypes.TabPages.Add(tabName); TabPage addedTab = tabMetadataTypes.TabPages[i]; //addedTab.Anchor = AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Top; addedTab.Controls.Add(child); } tabMetadataTypes.Visible = true; } } }