I am experimenting with the mediaservice event handler, to get a copy of the saved (uploaded) media items to another folder (aka backup).
The code
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
MediaService.Saved += MediaServiceSaved;
}
void MediaServiceSaved(IMediaService sender, SaveEventArgs<IMedia> e)
{
foreach (var mediaItem in e.SavedEntities)
{
var umbracoFileProperty = mediaItem.Properties["umbracoFile"].Value.ToString();
var newfile = .. get file path and server.mappath it
var fromPath = get target copy directory mappath
var fi = new System.IO.FileInfo(newfile);
if (!fi.Directory.Exists) fi.Directory.Create();
System.IO.File.Copy(fromPath,newfile);
}
}
When i save a single and/or multiple files from Media Section-> Upload, the file copy (backup) takes place fine but the UI throws error like
Transaction (Process ID 54) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
Any idea why this is happening? The file copy takes place fine (all within the same host so it occurs within a second or two), do I need to call some method to prevent this?
Would greatly appreciate if someone can shed some light on this.
MediaService Saved handler throwing SQL Deadlock
I am experimenting with the mediaservice event handler, to get a copy of the saved (uploaded) media items to another folder (aka backup).
The code
When i save a single and/or multiple files from Media Section-> Upload, the file copy (backup) takes place fine but the UI throws error like
Any idea why this is happening? The file copy takes place fine (all within the same host so it occurs within a second or two), do I need to call some method to prevent this?
Would greatly appreciate if someone can shed some light on this.
is working on a reply...