1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Delete File Associated with user account

Delete File Associated with user account

6 posts, 0 answered
  1. Brian
    Brian avatar
    31 posts
    Registered:
    25 Jun 2009
    25 Jun 2009
    Link to this post
    Hello all.  I'm developing a custom application that works inside Sitefinity & while this is the first time I've worked with Sitefinity everything seems to be going very well.  However I'm stuck on one issue that I'm not sure how to resolve.

    In my custom application users can upload pictures to their profile that is created in our custom app.  My issue is that if an admin user deletes any user account from within the admin site, I wanted the associated user images deleted off the hard drive.  I'm not sure in the admin how to capture what user is being deleted?  I looked in Users.aspx in the CmsAdmin folder but can't seem to find a way to make this happen.

    Any help would be appreciated!

    Thanks,

    Brian
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    25 Jun 2009
    Link to this post
    Hi Brian,

    If the images have been uploaded to the file system there is no reference to the item owner. You can delete the items that has been uploaded through Sitefinity Interface using Images and Documents module or Sitefinity API.

    Here is sample code that you need to add when deleting a user.

          ContentManager manager = new ContentManager("Libraries"); 
            IList listofAllitems = manager.GetContent(); 
            foreach (IContent cnt in listofAllitems) 
            { 
                StagedContent cont = manager.GetStagedContent(cnt.ID) as StagedContent;; 
                if(cont.Owner.Equals("admin")) 
                { 
                    manager.DeleteContent(cont); 
                } 
            } 

    The problem that I can see here is that if the user has used this items somewhere in pages or modules all references to this items will be lost.

    I hope this helps.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Brian
    Brian avatar
    31 posts
    Registered:
    25 Jun 2009
    25 Jun 2009
    Link to this post
    Ivan, Thanks for the reply.

    What I really need is the Sitefinity user id when the admin deletes a user.  If I could retrive that then I could write some custom code to delete the users images. 

    Sitefinity knows nothing about these image since they are part of my custom app.  But I would like to keep on the user management functions in one place.

    Any idea on how I can get the users ID that will be deleted?

    Thanks again,

    Brian
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    25 Jun 2009
    Link to this post
    Hi Brian,

    You can add the following logic under Sitefinity/CmsAdmin/Users.cs

        protected override void OnInit(EventArgs e) 
        { 
            base.OnInit(e); 
            manageUsers.ModeChanged += new EventHandler(manageUsers_ModeChanged); 
            manageUsers.CreatedRole += new RoleCreatedEventHandler(manageUsers_CreatedRole); 
            manageUsers.DeletingUser += new ModifingActionCancelEventHandler(manageUsers_DeletingUser); 
        } 
     
        void manageUsers_DeletingUser(object source, ModifingActionCancelEventArgs e) 
        { 
            string name = e.Username.ToString(); 
            MembershipUser user = UserManager.Default.GetUser(name); 
            string IDuser = user.ProviderUserKey.ToString(); 
     
        } 

    By doing so you are subscribing for manageUsers deleting event and then you are getting the ID of the user that is being deleted.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Brian
    Brian avatar
    31 posts
    Registered:
    25 Jun 2009
    25 Jun 2009
    Link to this post
    Ivan,

    Thank you very much!  That is exactly what I needed.

    Brian
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    25 Jun 2009
    Link to this post
    Hello Brian,

    Let us know if there is anything else that we can do for you.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
6 posts, 0 answered