// Index. aspx: displays the content of the xml file, and adds, deletes, and modifies the content.
- Using System;
- Using System. Data;
- Using System. Configuration;
- Using System. Collections;
- Using System. Web;
- Using System. Web. Security;
- Using System. Web. UI;
- Using System. Web. UI. WebControls;
- Using System. Web. UI. WebControls. WebParts;
- Using System. Web. UI. HtmlControls;
- Using LTP. Accounts. Bus;
- Using System. Xml;
- Using System. Text;
- Using System. Xml. XPath;
- Using System. IO;
- Using System. Text. RegularExpressions;
- Public partial class Home_Pic_index: PageBase
- {
- // Int PermId_Add = 45; // Add product Permissions
- // Int PermId_Search = 47; // query product Permissions
- // Int PermId_Modify = 48; // modify product Permissions
- // Int PermId_Delete = 49; // Delete the product permission
- Protected void Page_Load (object sender, EventArgs e)
- {
- If (! Page. IsPostBack)
- {
- // Initialize the insert position
- String file = Server. MapPath (ConfigurationManager. etettings ["XmlFile"]);
- XmlDocument doc = new XmlDocument ();
- Doc. Load (file );
- XmlElement root = doc. DocumentElement;
- // 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.
- Int count = root. ChildNodes. Count 1;
- TxtPos. Text = count. ToString ();
- DataBind1 ();
- }
- }
- # Add BtnAdd_Click to region
- /// <Summary>
- /// Add a new node
- /// </Summary>
- /// <Param name = "sender"> </param>
- /// <Param name = "e"> </param>
- Protected void BtnAdd_Click (object sender, EventArgs e)
- {
- String strPicName = "";
- // Image Processing
- LJH. Common. UploadFile previusfile = new LJH. Common. UploadFile ();
- // Set the destination address of the uploaded file
- Previusfile. UpFilePath = Server. MapPath ("~ /Pic ");
- // Set the virtual path of the Server File
- Previusfile. PicUrl = "pic /";
- // If the uploaded image is empty, the content of the EZ_PicPath field remains unchanged.
- If (String. IsNullOrEmpty (uploadModify. PostedFile. FileName ))
- {
- Return;
- }
- If (! Regex. IsMatch (uploadModify. PostedFile. FileName, ". [.] {1} jpg |. [.] {1} gif |. [.] {1} png "))
- {
- Lstrap. Common. MessageBox. Show (this, "Enter the image in the format of *. jpg! ");
- Return;
- }
- StrPicName = previusfile. fileSaveAs (uploadModify. PostedFile );
- Try
- {
- WriteXmlData (strPicName, Convert. ToInt32 (txtPos. Text ));
- Lstrap. Common. MessageBox. Show (this, "added successfully! ");
- }
- Catch
- {
- Lstrap. Common. MessageBox. Show (this, "failed to add! ");
- }
- DataBind1 ();
- }
- # Endregion