I have a media type of 'Meeting' with several properties including 2 uploads. I want to programmatically remove from the media type and the disk. I can get the media type node easily:
Media m = new Media(Convert.ToInt32(ddlDocList.SelectedValue));
Hmm bit confused now, I've looked up the property delete in the Umbraco source:
foreach (cms.businesslogic.property.Property p in this.getProperties)
if (p.PropertyType.DataTypeDefinition.DataType.Id == uploadField.Id &&
p.Value.ToString() != "" &&
System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath(p.Value.ToString()))
)
{
System.IO.File.Delete(System.Web.HttpContext.Current.Server.MapPath(p.Value.ToString()));
From which I created my code to this:
if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath(ddlDocList.SelectedValue.ToString())))
{
System.IO.File.Delete(System.Web.HttpContext.Current.Server.MapPath(ddlDocList.SelectedValue.ToString()));
}
Which successfully removes the file from the file system, of course, but the filename remains on the media content. I tried p.delete on the property, but that appeared to delete the property node and caused a problem with that media.
if (System.IO.File.Exists(docPath))
{
System.IO.File.Delete(docPath);
Media m = new Media(Convert.ToInt32(HttpContext.Current.Session["nodeid"]));
m.getProperty(HttpContext.Current.Session["property"].ToString()).Value = String.Empty;
umbraco.library.UpdateDocumentCache(m.Id);
}
Thanks for the advice. They are the same fortunately. The reason for the programmatic deletion is we do not give the users access to the Umbraco back-end.
Delete File Upload Programmatically
Hi all,
I have a media type of 'Meeting' with several properties including 2 uploads. I want to programmatically remove from the media type and the disk. I can get the media type node easily:
Can I now use m to delete the property?
Thanks,
Darryl
Hmm bit confused now, I've looked up the property delete in the Umbraco source:
From which I created my code to this:
However this does not seem to do anything at all.
Any help?
Cos the file didn't exist, duh!, Anyway I updated the code to this:
Which successfully removes the file from the file system, of course, but the filename remains on the media content. I tried p.delete on the property, but that appeared to delete the property node and caused a problem with that media.
Still not working :(
Darryl,
Whats the exception? (If any)
Chris
Working now Chris, thanks for your response. Here's the code I managed to get it working with:
Darryl,
Not sure if you have multiple environments, if you do be careful the nodeId's in your if statement remain constant.
We use courier here, so the nodeId's on the production box do not match that of the dev box.
Thanks,
Chris.
Thanks for the advice. They are the same fortunately. The reason for the programmatic deletion is we do not give the users access to the Umbraco back-end.
is working on a reply...