Exemple #1
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            string sXML = String.Empty;

            if (upFile.HasFile)
            {
                using (StreamReader sr = new StreamReader(upFile.FileContent)) {
                    sXML = sr.ReadToEnd();
                }
            }
            string sTest = String.Empty;

            if (!string.IsNullOrEmpty(sXML) && sXML.Length > 500)
            {
                sTest = sXML.Substring(0, 250).ToLower();

                try {
                    if (sXML.Contains("<channel>") && sXML.Contains("<rss"))
                    {
                        int iChnl = sXML.IndexOf("<channel>");
                        sTest = sXML.Substring(0, iChnl).ToLower();
                    }

                    if (sTest.Contains("<!-- this is a wordpress extended rss file generated by wordpress as an export of your") &&
                        sTest.Contains("http://purl.org/rss") &&
                        sTest.Contains("http://wordpress.org/export"))
                    {
                        WordPressSite wps = ContentImportExportUtils.DeserializeWPExportAll(sXML);
                        ContentImportExportUtils.AssignWPExportNewIDs(SiteData.CurrentSite, wps);
                        ContentImportExportUtils.SaveSerializedDataExport <WordPressSite>(wps.NewSiteID, wps);

                        Response.Redirect(CreateLink("WPGalleryImport", String.Format("id={0}", wps.NewSiteID)));
                    }

                    lblWarning.Text = "File did not appear to match an expected format.";
                    lblWarning.Attributes["style"] = "color: #990000;";
                } catch (Exception ex) {
                    lblWarning.Text = ex.ToString();
                    lblWarning.Attributes["style"] = "color: #990000;";
                }
            }
            else
            {
                lblWarning.Text = "No file appeared in the upload queue.";
                lblWarning.Attributes["style"] = "color: #990000;";
            }
        }
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            string sXML = "";

            if (upFile.HasFile)
            {
                using (StreamReader sr = new StreamReader(upFile.FileContent)) {
                    sXML = sr.ReadToEnd();
                }
            }
            string sTest = "";

            if (!String.IsNullOrEmpty(sXML) && sXML.Length > 500)
            {
                sTest = sXML.Substring(0, 250).ToLower();

                try {
                    if (sTest.Contains("<contentpageexport xmlns:xsi=\"http://www.w3.org/2001/xmlschema-instance\" xmlns:xsd=\"http://www.w3.org/2001/xmlschema\">"))
                    {
                        ContentPageExport cph = ContentImportExportUtils.DeserializeContentPageExport(sXML);
                        ContentImportExportUtils.AssignContentPageExportNewIDs(cph);
                        ContentImportExportUtils.SaveSerializedDataExport <ContentPageExport>(cph.NewRootContentID, cph);

                        if (cph.ThePage.ContentType == ContentPageType.PageType.ContentEntry)
                        {
                            Response.Redirect(SiteFilename.PageAddEditURL + "?importid=" + cph.NewRootContentID.ToString());
                        }
                        else
                        {
                            Response.Redirect(SiteFilename.BlogPostAddEditURL + "?importid=" + cph.NewRootContentID.ToString());
                        }
                    }

                    if (sTest.Contains("<siteexport xmlns:xsi=\"http://www.w3.org/2001/xmlschema-instance\" xmlns:xsd=\"http://www.w3.org/2001/xmlschema\">"))
                    {
                        SiteExport site = ContentImportExportUtils.DeserializeSiteExport(sXML);
                        ContentImportExportUtils.AssignSiteExportNewIDs(site);
                        ContentImportExportUtils.SaveSerializedDataExport <SiteExport>(site.NewSiteID, site);

                        Response.Redirect(SiteFilename.SiteImportURL + "?importid=" + site.NewSiteID.ToString());
                    }

                    if (sXML.Contains("<channel>") && sXML.Contains("<rss"))
                    {
                        int iChnl = sXML.IndexOf("<channel>");
                        sTest = sXML.Substring(0, iChnl).ToLower();
                    }

                    if (sTest.Contains("<!-- this is a wordpress extended rss file generated by wordpress as an export of your") &&
                        sTest.Contains("http://purl.org/rss") &&
                        sTest.Contains("http://wordpress.org/export"))
                    {
                        WordPressSite wps = ContentImportExportUtils.DeserializeWPExport(sXML);
                        ContentImportExportUtils.AssignWPExportNewIDs(SiteData.CurrentSite, wps);
                        ContentImportExportUtils.SaveSerializedDataExport <WordPressSite>(wps.NewSiteID, wps);

                        Response.Redirect(SiteFilename.WPSiteImportURL + "?importid=" + wps.NewSiteID.ToString());
                    }

                    lblWarning.Text = "File did not appear to match an expected format.";
                    lblWarning.Attributes["style"] = "color: #990000;";
                } catch (Exception ex) {
                    lblWarning.Text = ex.ToString();
                    lblWarning.Attributes["style"] = "color: #990000;";
                }
            }
            else
            {
                lblWarning.Text = "No file appeared in the upload queue.";
                lblWarning.Attributes["style"] = "color: #990000;";
            }
        }