Code sample or documentation for creating posts

Mar 8, 2009 at 10:02 PM
Anybody know where to find code samples or documentation on creating posts for BlogEngine.Net from code?

I have a Community Server database without a front-end (I had too many problems with my web host so I dropped them). I know how to get the posts out of the CS database, I just want to know how to get them into BlogEngine.Net. I'm hoping it's fairly simple. It would be great if I just had to create the XML and stick it in the right directory, but before I go doing something crazy like that, I want to verify that there isn't anything else I need to be updating.
Mar 9, 2009 at 3:57 AM
Someone else probably knows more about this than me, but you can import data (posts, I believe) into BE on the Settings tab in the control panel.  At the bottom of the page, you'll see an Import & Export section.  You can see there's two different formats supported for importing data -- BlogML and RSS.
Mar 9, 2009 at 5:32 AM
Edited Mar 9, 2009 at 5:45 AM
I figured it out. It seems like all you need to do is generate the xml files for the post and put them in the post directory. However, I ended up using the web services AddPost method. I included the code I used to import the files (the sql I used is below the second horizontal rule). It seems the web service does not support tags or the previousUrl parameter which is why I didn't bother using them (I'm using version 1.4.5). The code is crude, but it seems to have worked. I did forget to use a category so I'll have to probably go through my posts and categorize them (I have to tag them anyway).

        private static void Import()
            var conn = new SqlConnection(@"SERVER=***;DATABASE=***;TRUSTED_CONNECTION=true;");
            var rootPath = @".\Posts";


            var svc = new BlogEngine.BlogImporter.BlogImporterSoapClient();
                var cmd = new SqlCommand(My.Resources.SQL_GetPosts, conn);
                var dr = cmd.ExecuteReader();
                    var hdr = new BlogEngine.BlogImporter.AuthHeader();
                    hdr.Username = "***";
                    hdr.Password = "***";
                    var post = new BlogEngine.BlogImporter.ImportPost();
                    post.Author = (string)dr["PostAuthor"];
                    post.Title = (string)dr["Subject"];
                    post.PostDate = (DateTime)dr["PostDate"];
                    post.Content = (string)dr["Body"];

                    svc.AddPost(hdr, post, null, true);
                conn = null;
                svc = null;

SELECT PostID, PostAuthor, Subject, PostName, PostDate, Body
    FROM cs_Posts
    WHERE ApplicationPostType = 1
        AND PostType = 1
    ORDER BY PostDate

SELECT p.PostID, c.Name
    FROM cs_Posts_InCategories pc
        LEFT JOIN cs_Post_Categories c ON (pc.CategoryID = c.CategoryID)
        LEFT JOIN cs_Posts p ON (pc.PostID = p.PostID)
    ORDER BY pc.PostID
Mar 9, 2009 at 5:43 AM
Thanks for sharing that code.  I noticed you blanked out your DB connection details, but it looks like your Blog Username/Password is still in there ... :)
Mar 9, 2009 at 5:46 AM
Thanks for letting me know. Guess I'll have to change my password :)