Copied to clipboard

Flag this post as spam?

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


  • Srinivasan 2 posts 72 karma points
    1 week ago
    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 419 posts 2527 karma points MVP c-trib
    1 week ago
    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