Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ivan 165 posts 543 karma points
    Jan 10, 2013 @ 17:34
    Ivan
    0

    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?

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 10, 2013 @ 17:54
    Jan Skovgaard
    0

    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

  • Ivan 165 posts 543 karma points
    Jan 10, 2013 @ 18:14
    Ivan
    0

    Hi Jan.

    The file is deleted via the backoffice.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 10, 2013 @ 23:41
    Jan Skovgaard
    0

    Hi Ivan

    So when you delete it in the backoffice do you then mark the "Remove file" checkbox as well?

    /Jan

  • Ivan 165 posts 543 karma points
    Jan 11, 2013 @ 09:28
    Ivan
    0

    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?

Please Sign in or register to post replies

Write your reply to:

Draft