Use asp.net programming to process xml sorting code

Source: Internet
Author: User

// Index. aspx: displays the content of the xml file, and adds, deletes, and modifies the content.

  1. Using System;
  2. Using System. Data;
  3. Using System. Configuration;
  4. Using System. Collections;
  5. Using System. Web;
  6. Using System. Web. Security;
  7. Using System. Web. UI;
  8. Using System. Web. UI. WebControls;
  9. Using System. Web. UI. WebControls. WebParts;
  10. Using System. Web. UI. HtmlControls;
  11. Using LTP. Accounts. Bus;
  12. Using System. Xml;
  13. Using System. Text;
  14. Using System. Xml. XPath;
  15. Using System. IO;
  16. Using System. Text. RegularExpressions;
  17. Public partial class Home_Pic_index: PageBase
  18. {
  19. // Int PermId_Add = 45; // Add product Permissions
  20. // Int PermId_Search = 47; // query product Permissions
  21. // Int PermId_Modify = 48; // modify product Permissions
  22. // Int PermId_Delete = 49; // Delete the product permission
  23. Protected void Page_Load (object sender, EventArgs e)
  24. {
  25. If (! Page. IsPostBack)
  26. {
  27. // Initialize the insert position
  28. String file = Server. MapPath (ConfigurationManager. etettings ["XmlFile"]);
  29. XmlDocument doc = new XmlDocument ();
  30. Doc. Load (file );
  31. XmlElement root = doc. DocumentElement;
  32. // At this time, count 1 is set to add data to the end of the node of the xml file when you click submit directly.
  33. Int count = root. ChildNodes. Count 1;
  34. TxtPos. Text = count. ToString ();
  35. DataBind1 ();
  36. }
  37. }
  38. # Add BtnAdd_Click to region
  39. /// <Summary>
  40. /// Add a new node
  41. /// </Summary>
  42. /// <Param name = "sender"> </param>
  43. /// <Param name = "e"> </param>
  44. Protected void BtnAdd_Click (object sender, EventArgs e)
  45. {
  46. String strPicName = "";
  47. // Image Processing
  48. LJH. Common. UploadFile previusfile = new LJH. Common. UploadFile ();
  49. // Set the destination address of the uploaded file
  50. Previusfile. UpFilePath = Server. MapPath ("~ /Pic ");
  51. // Set the virtual path of the Server File
  52. Previusfile. PicUrl = "pic /";
  53. // If the uploaded image is empty, the content of the EZ_PicPath field remains unchanged.
  54. If (String. IsNullOrEmpty (uploadModify. PostedFile. FileName ))
  55. {
  56. Return;
  57. }
  58. If (! Regex. IsMatch (uploadModify. PostedFile. FileName, ". [.] {1} jpg |. [.] {1} gif |. [.] {1} png "))
  59. {
  60. Lstrap. Common. MessageBox. Show (this, "Enter the image in the format of *. jpg! ");
  61. Return;
  62. }
  63. StrPicName = previusfile. fileSaveAs (uploadModify. PostedFile );
  64. Try
  65. {
  66. WriteXmlData (strPicName, Convert. ToInt32 (txtPos. Text ));
  67. Lstrap. Common. MessageBox. Show (this, "added successfully! ");
  68. }
  69. Catch
  70. {
  71. Lstrap. Common. MessageBox. Show (this, "failed to add! ");
  72. }
  73. DataBind1 ();
  74. }
  75. # Endregion

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.