The approach for multimedia links is the same as for component links. And it also applies to both content and metadata fields. This example sets the link to the mm component in the metadata in the folder where the md diagram contains a sub-field named "versioned_component" containing the "component" field, which is the link field for multimedia components
this.OpenSession(); try { //itemUri is the MM Component uri var currentItem = (ComponentData)session.Read(itemUri, new ReadOptions()); LinkToRepositoryData ltrd = currentItem.LocationInfo.ContextRepository; var pd = (PublicationData)session.Read(ltrd.IdRef, new ReadOptions()); String currentPublicationWebdavURL = pd.LocationInfo.WebDavUrl; String schemaUri = string.Format(FOLDER_MD_SCHEMA_WEBDAVURL, HttpUtility.UrlDecode(currentPublicationWebdavURL)); //schemaUri = HttpUtility.UrlEncode(schemaUri); var sd = (SchemaData)session.Read(schemaUri, new ReadOptions()); FolderData folder = new FolderData(); folder.Id = TcmUri.UriNull; folder.Title = "hidden_" + Guid.NewGuid().ToString(); var rootFolder = (FolderData)session.Read( currentItem.LocationInfo.OrganizationalItem.IdRef, new ReadOptions()); folder.LocationInfo= new LocationInfo() { OrganizationalItem = new LinkToOrganizationalItemData(){ IdRef = rootFolder.Id } }; folder.MetadataSchema = new LinkToSchemaData() { IdRef = sd.Id, }; string sMetadata = "<Metadata xmlns=\"{0}\" xmlns:xlink=\"{1}\"> " + " <version_component>" + " <component xlink:type=\"simple\" " + " xlink:href=\"{2}\" xlink:title=\"{3}\" />" + " </version_component> " + "</Metadata>"; sMetadata = string.Format(sMetadata, sd.NamespaceUri, Tridion.Constants.XlinkNamespace, currentItem.Id.ToString(), currentItem.Title); folder.Metadata = sMetadata; folderUri = session.Save(folder, new ReadOptions()).Id.ToString(); return folderUri; } finally { this.CloseSession(); }
Hope this helps too
source share