Copied to clipboard

Flag this post as spam?

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


  • Toni Becker 146 posts 425 karma points
    Aug 28, 2011 @ 20:31
    Toni Becker
    0

    Event deleting related media folder

    Hy everybody i've created an event creating my users; doctyperelated Media and so on.

    Now for better handling of the backoffice  i need to create an event wich is deleting the related mediafolder to the document. heres my code so far.

    namespace ClientFolder 
    {
        public class ClientFolder : umbraco.BusinessLogic.ApplicationBase
        {
            public ClientFolder()
            {
                Document.AfterPublish += new Document.PublishEventHandler(Document_AfterPublish);
                Document.AfterDelete += new Document.DeleteEventHandler(Document_AfterDelete);
            }
    
            void Document_AfterDelete(Document sender, DeleteEventArgs e)
            {
                if(sender.ContentType.Alias == "WebsiteContainer")
                {
                    MediaType folderType = MediaType.GetByAlias("Folder");
    
                    if(FolderExists(sender.Text))
                    {
                        //now take the same folder from mediasection and delete
                    }
                }
    
            }
    
    
            void Document_AfterPublish(Document sender, PublishEventArgs e)
            {
    
                if (sender.ContentType.Alias == "WebsiteContainer")
                {
                    string websiteName = sender.Text;
                    string myUser = websiteName;
                    string myUserMail = "[email protected]";
    
    
                    MediaType folderType = MediaType.GetByAlias("Folder");
                    UserType demoUserType = UserType.GetUserType(2);
    
    
                    if (!FolderExists(sender.Text))
                    {
                        Media.MakeNew(websiteName, folderType, new User(0),-1);
                        DocumentType newDt = DocumentType.MakeNew(new User(0), "WebsiteContainer");
                        newDt.Description = "Seite des neuen Kunden";
                        newDt.Text = websiteName;
                    }
    
                    if(!UserExists(sender.Text))
                    {
                        User u = User.MakeNew(websiteName, myUser, hashPassword("111111"), myUserMail, demoUserType);
                        u.addApplication("content");
                        u.addApplication("media");
                        u.Save();
                    }
    
                }
    
            }
    
    
    
            private bool UserExists(string userName)
            {
                foreach (var myUser in User.getAll())
                {
                   if(myUser.LoginName == userName)
    
                       return true;
                }
                return false;
            }
    
    
            private bool FolderExists(string folderName)
            {
                foreach (var item in Media.GetRootMedias()) 
                {
                    if (item.Text == folderName)
                        return true;
                }
                return false;
            }
    
            string hashPassword(string password)
            {
    
                HMACSHA1 hash = new HMACSHA1();
                hash.Key = Encoding.Unicode.GetBytes(password);
                string encodedPassword = Convert.ToBase64String(hash.ComputeHash(Encoding.Unicode.GetBytes(password)));
                return encodedPassword;
            }
    
    
        }

    Thanks for all help

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Aug 29, 2011 @ 12:59
    Sebastiaan Janssen
    0

    Not sure I understand: So when you delete a content item, the media item that has been picked on that content item should be deleted as well AND the folder in which the media item is should be deleted?

    And by "folder" do you mean the mediatype Folder or the folder on disk?

  • Toni Becker 146 posts 425 karma points
    Aug 29, 2011 @ 13:23
    Toni Becker
    0

    I'll explain :)

    So first step is i've created a so-called MasterDocType with Alias WebsiteContainer
    2. I Create in ContentSection my Node let's say Client Site 1 (DocType-WebsiteContainer)
    3. The Event creates automatically a MediaFolder with the Name Client Site 1 in the Media Section/ a User with Name Client Site 1 and a new DocType Client Site 1

    Wy all this: I'm using this one install for different small websites on my clients with a separate Backend developed and feeded with data from the webservice 

    For better workflow i've created this event to save time and not doing click click click and so on. But i need to create an Delete event wich deletes the same Media Folder (sender is holding the name etc.), when i delete the Node in the Content Section.

    I hope my explanation is not so difficult, cause my english is not the best :p

Please Sign in or register to post replies

Write your reply to:

Draft