惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
罗磊的独立博客
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
云风的 BLOG
云风的 BLOG
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
A
About on SuperTechFans
WordPress大学
WordPress大学
B
Blog
Martin Fowler
Martin Fowler
Jina AI
Jina AI
I
InfoQ
P
Proofpoint News Feed
小众软件
小众软件
S
SegmentFault 最新的问题
V
V2EX
B
Blog RSS Feed
量子位
大猫的无限游戏
大猫的无限游戏
aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
MongoDB | Blog
MongoDB | Blog
美团技术团队

博客园 - 彷徨......

轻巧地,我走了 Unable to load print control in ReportingService reporting service报表设计时候页面宽度高度的设置 -转 Beginning SQL Server 2005 Reporting Services Sharepoint Server与Reporting Services整合配置 -转 T61装win2003后的驱动安装 一篇绝好的讲sql server索引的文章,值得收藏 使用Div自动换行一事 一个检查SPN的小工具 Create many user to ducumentum contentserver "Personalize" property is invalid in moss2010 - 彷徨...... 这个破备案制度 可恶的小偷 转:HowTo: Deploy .NET ActiveX Control How to overwrite the method in Javascript SEO工具大全-转 dsa XmlDocument的Load方法报“hexadecimal value .., is an invalid character” - 彷徨...... 出来了没有呢?
使用metablog迁移博客园的文章 - 彷徨...... - 博客园
彷徨...... · 2010-07-02 · via 博客园 - 彷徨......

有时候我们希望能将自己所有博客园的文章迁移到其他的博客site,大家可能最先想到的就是metablog,没错,只有它了。
首先搜索了一下,很容易搜到老赵这篇文章 "一次批量修改博客文章的经验".  我个人不懂F#,也不太喜欢老赵的做法,就重新考虑了一下。

和老赵有一样的问题, metaBlog的API中的getRecentPosts并无法取得所有的文章,而且速度极慢,中间不能实现异步,无法看到即时结果。 后来无意发现将博客园所有文章备份后所生成的xml中其实已经包含了所有的文章id,这是个好兆头。
接下来工作就简单了,分析该xml文件,取得所有文章id,然后调用getPost分别取每篇文章的内容,然后迁移到其他的博客地址,这样就可以即时看到每一篇的迁移结果了。

下边是其中主要代码

                       XmlDocument docment = new XmlDocument();
                        docment.Load("c:\\blogMigr\\CNBlogs_BlogBackup_1_200606_201006 - Copy.xml");
                        XmlNodeList list = docment.SelectNodes("/rss/channel/item");

                        int nCount = 0;

                        foreach (XmlNode item in list)
                        {
                            nCount++;
                            string link = item.SelectSingleNode("link").InnerText;
                            string postId = link.Substring(link.LastIndexOf('/') + 1);
                            postId = postId.Substring(0, postId.IndexOf('.'));

                            Post postOld = oldSpace.getPost(postId, oldUsername, newPassword);

                            if ("" == postOld.title)
                            {
                                Console.WriteLine("Maybe this is a draft!");
                                oldSpace.deletePost(String.Empty, "" + postOld.postid, oldUsername, oldPassword, true);
                                Console.WriteLine("Delete draft from old Space, OK!");
                                continue;
                            }

                            Post postNew = new Post();
                            postNew.title = postOld.title;
                            postNew.dateCreated = postOld.dateCreated;
                            postNew.categories = postOld.categories;
                            postNew.description = postOld.description;
                            string newId = newSpace.newPost("Myblog", newUsername, newPassword, postNew, true);

                            lblStatus.Invoke(new processLable(delegate()
                            {
                                lblStatus.Text = string.Format("The application have processed {0} postes. {1}", nCount, postNew.title);
                            }
                            ));
                        }