Very VERY unfinished:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WPimport.ascx.cs" Inherits="SitefinityWebApp.Widgets.WPimport" %>
<div>
<div style="color: red;"> <asp:Literal ID="Error" Visible="false" runat="server" /> </div>
<div> <asp:Label AssociatedControlID="WordPressFile" runat="server">WordPress Export File: </asp:Label> <asp:FileUpload ID="WordPressFile" runat="server" /> </div>
<div> <asp:Label AssociatedControlID="BlogDestination" runat="server">Import into this blog: </asp:Label> <asp:DropDownList ID="BlogDestination" runat="server"> <asp:ListItem Value="">No blogs found!</asp:ListItem> </asp:DropDownList> </div>
<div> <asp:Label AssociatedControlID="CreateTags" runat="server">Create the tags? </asp:Label> <asp:DropDownList ID="CreateTags" runat="server"> <asp:ListItem>Yes</asp:ListItem> <asp:ListItem>No</asp:ListItem> </asp:DropDownList> </div>
<div> <asp:Label AssociatedControlID="CreateCategories" runat="server">Create the categories? </asp:Label> <asp:DropDownList ID="CreateCategories" runat="server"> <asp:ListItem>Yes</asp:ListItem> <asp:ListItem>No</asp:ListItem> </asp:DropDownList> </div>
<div> <asp:Button ID="Submit" Text="Let's do this!" runat="server" onclick="Submit_Click" /> </div>
</div>
<asp:PlaceHolder ID="ImportResults" Visible="false" runat="server">
<hr />
<asp:Repeater ID="ImportMessagesRepeater" runat="server"> <HeaderTemplate> <ul> </HeaderTemplate> <ItemTemplate> <li><%# Container.DataItem %></li> </ItemTemplate> <FooterTemplate> </ul> </FooterTemplate> </asp:Repeater>
</asp:PlaceHolder>using System;using System.Collections.Generic;using System.Linq;using Telerik.Sitefinity;using System.Xml.Linq;
namespace SitefinityWebApp.Widgets{ public partial class WPimport : System.Web.UI.UserControl { protected List<string> ImportMessages = new List<string>();
protected void Page_Load(object sender, EventArgs e) { var blogs = App.WorkWith().Blogs().Get().ToList(); BlogDestination.DataValueField = "Id"; BlogDestination.DataTextField = "Title"; BlogDestination.DataSource = blogs; BlogDestination.DataBind(); }
protected void Submit_Click(object sender, EventArgs e) { if (BlogDestination.SelectedValue == "") { ShowError("No blog was selected."); return; }
if (WordPressFile.HasFile == false) { ShowError("No WordPress import file was included."); return; }
XNamespace wp = "http://wordpress.org/export/1.1/"; XNamespace content = "http://purl.org/rss/1.0/modules/content/"; var xml = XDocument.Load(WordPressFile.FileContent);
// Tags var tags = xml.Descendants(wp + "tag") .Select(t => new { Slug = t.Element(wp + "tag_slug").Value }) .ToList();
// Posts var posts = xml.Descendants("item") .Where(t => t.Element(wp + "post_type").Value == "post") .Where(t => t.Element(wp + "status").Value == "publish") .Select(t => new { Title = t.Element("title").Value, Link = t.Element("link").Value, PubDate = t.Element("pubDate").Value, Encoded = t.Element(content + "encoded"), Tags = t.Elements("category").Where(b => (string)b.Attribute("domain") == "post_tag").Select(c => c.Value).ToList() }) .ToList();
// Tons of things to do: // -------------------------------------- // - Import Categories // - Import Images // - Import Comments // - Wrap <p> tags around the paragraphs in WordPress posts // - Create Sitefinity tags, categories, images & blog posts using the Sitefinity API // - Preserve URL's and/or establish 301 redirects
foreach (var tag in tags) { ShowImportMessage("Tag: " + tag.Slug); }
foreach (var post in posts) { ShowImportMessage("Post: " + post.Title); }
ImportMessagesRepeater.DataSource = ImportMessages; ImportMessagesRepeater.DataBind(); }
private void ShowImportMessage(string Message) { ImportResults.Visible = true; ImportMessages.Add(Message); }
private void ShowError(string ErrorMessage) { Error.Visible = true; Error.Text = ErrorMessage; } }}



