PageRenderTime 13ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 1ms

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

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