Copied to clipboard

Flag this post as spam?

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


  • Srinivasan 10 posts 80 karma points
    Aug 09, 2019 @ 14:46
    Srinivasan
    0

    I need to create folder when xml import by using cmsimport.

    my goal is creating a folder in content menu, when xml import.

    I don't know, in which event need to put the code,

    but i trying below code , two method is calling continuously in loop, finally overflow exception is showed

    private void ContentServiceSaving(IContentService sender, SaveEventArgs<IContent> args)
                    {
    
                        var contentService = ApplicationContext.Current.Services.ContentService;
                        MyEventHandler myEventHandler = new MyEventHandler();
                        myEventHandler.CreatePage("Dummyfolder1", 15239, "Folder", "dummydata");
    
                    }
    
                    private bool CreatePage(string name, int parentPageId, string docTypeAlias, string someData)
                    {
                        var contentService = ApplicationContext.Current.Services.ContentService;
                        var publishDate = DateTime.Now;
                        var content = contentService.CreateContent(name, parentPageId, docTypeAlias);
                        content.ReleaseDate = publishDate;
                        content.CreateDate = publishDate;enter code here
                        content.UpdateDate = publishDate;
                        object somedata = 12345;
                        var result = contentService.SaveAndPublishWithStatus(content);
                        return result.Success;
                    }
    
  • Søren Kottal 712 posts 4570 karma points MVP 6x c-trib
    Aug 13, 2019 @ 18:44
    Søren Kottal
    1

    Hi Srinivasan

    Welcome to Our, the friendly community.

    The reason for your infinite loop, is the calling of contentService.SaveAndPublishWithStatus(content).

    You need to use the overload, which doesn't raise events, as your ContentServiceSaving event, will trigger your CreatePage method again, creating a new "Dummyfolder1" page. This will then raise the ContentServiceSaving event again, and further on...

    IIRC, you can add false as the second parameter for SaveAndPublishWithStatus, but check with Intellisense, just to be sure.

Please Sign in or register to post replies

Write your reply to:

Draft