Skip to content

Instantly share code, notes, and snippets.

@DominicCronin
Created January 13, 2015 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DominicCronin/fcc3397a21bda19f4cb8 to your computer and use it in GitHub Desktop.
Save DominicCronin/fcc3397a21bda19f4cb8 to your computer and use it in GitHub Desktop.
Add Component Id to Binary Filename
// componentUri is a TcmUri representing the id of the binary component that you want to publish
// This snippet shows how you can add the item id to the filename.
var component = (Component)engine.GetObject(componentUri);
var filename = component.BinaryContent.Filename
extension = Path.GetExtension(filename);
filename = Path.GetFileNameWithoutExtension(filename);
filename = String.Concat(filename, "_", componentUri.ItemId.ToString(), extension);
engine.AddBinary(component.Id, null, null, component.BinaryContent.GetByteArray(), filename);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment