PageRenderTime 66ms CodeModel.GetById 58ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/admin/Settings/Import.aspx.cs

#
C# | 50 lines | 37 code | 7 blank | 6 comment | 2 complexity | 7f43da74015bc81a67f50a963c0e5cbb MD5 | raw file
 1namespace admin.Settings
 2{
 3    using System;
 4    using System.IO;
 5    using BlogEngine.Core.API.BlogML;
 6    using App_Code;
 7
 8    public partial class Import : System.Web.UI.Page
 9    {
10        protected void Page_Load(object sender, EventArgs e)
11        {
12            WebUtils.CheckRightsForAdminSettingsPage(false);
13        }
14
15        /// <summary>
16        /// Handles the Click event of the btnBlogMLImport control.
17        /// </summary>
18        /// <param name="sender">The source of the event.</param>
19        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
20        protected void BtnBlogMlImportClick(object sender, EventArgs e)
21        {
22            var fileName = txtUploadFile.FileName;
23
24            if (string.IsNullOrEmpty(fileName))
25            {
26                //this.Master.SetStatus("warning", "File name is required");
27            }
28            else
29            {
30                var reader = new BlogReader();
31
32                var stm = txtUploadFile.FileContent;
33                var rdr = new StreamReader(stm);
34                reader.XmlData = rdr.ReadToEnd();
35
36                string tmpl = "<script language=\"JavaScript\">ShowStatus('{0}', '{1}');</script>";
37
38                if(reader.Import())
39                {
40                    tmpl = string.Format(tmpl, "success", reader.Message);
41                }else
42                {
43                    tmpl = string.Format(tmpl, "warning", reader.Message.Replace("'", "`").Replace("\"", "`").Replace(Environment.NewLine, " "));
44                }
45
46                ClientScript.RegisterStartupScript(this.GetType(), "ImportDone", tmpl);
47            }
48        }
49    }
50}