Created Media node pragmatically. But can't remove it afterwards.
Hi guys.
When I create a Media node (.png file) using API, I can't remove the one from the file system on the server, even though the corresponding node had been removed in Umbraco backend.
The code creating Media node is as follows:
Media f = Media.MakeNew("file1.png", MediaType.GetByAlias("file"), new User(0), 1234);
Created Media node pragmatically. But can't remove it afterwards.
Hi guys.
When I create a Media node (.png file) using API, I can't remove the one from the file system on the server, even though the corresponding node had been removed in Umbraco backend.
The code creating Media node is as follows:
Media f = Media.MakeNew("file1.png", MediaType.GetByAlias("file"), new User(0), 1234);
string mediaPath = HttpContext.Current.Server.MapPath("~/media/");
Directory.CreateDirectory(mediaPath + f.Id);
file.SaveAs(string.Format(("{0}/{1}/{2}"), mediaPath, f.Id, fName));
f.getProperty("umbracoFile").Value = string.Format("/{0}/{1}", f.Id, fName);
Any thoughts?
Hi Ivan
How are you trying to delete the file?
Are you trying to delete it from within the Umbraco backoffice or using the API?
/Jan
Hi Jan.
The file is deleted via the backoffice.
Hi Ivan
So when you delete it in the backoffice do you then mark the "Remove file" checkbox as well?
/Jan
Hi Jan.
When I do mark the checkbox, the file is removed, yes. But the folder containing the file is NOT removed.
Whereas if I created a file via backend and then removed it, the contaning folder would be removed as well.
My guess is that in the code above the folder name wasn't specified correctly (see file.SaveAs method). Can you take a look?
is working on a reply...