private void ModifyImageNativeAPI(Guid masterImageId, string newTitle, Stream imageStream, string imageExtension)
{
LibrariesManager librariesManager = LibrariesManager.GetManager();
//Get the master version.
Image master = librariesManager.GetImages().Where(i => i.Id == masterImageId).FirstOrDefault();
if (master != null)
{
//Check out the master to get a temp version.
Image temp = librariesManager.Lifecycle.CheckOut(master) as Image;
//Make the modifications to the temp version.
temp.Title = newTitle;
temp.LastModified = DateTime.UtcNow;
temp.Urls.Clear();
temp.UrlName = Regex.Replace(newTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
librariesManager.Upload(temp, imageStream, imageExtension);
//Checkin the temp and get the updated master version.
//After the check in the temp version is deleted.
master = librariesManager.Lifecycle.CheckIn(temp) as Image;
librariesManager.SaveChanges();
//Publish the image.
var bag = new Dictionary<string, string>();
bag.Add("ContentType", typeof(Image).FullName);
WorkflowManager.MessageWorkflow(masterImageId, typeof(Image), null, "Publish", false, bag);
}
}