123

 

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    
<appSettings>
        
<add key="PicPath" value="D:StudySampleCSharpAddTextToPic">iuu</add>
        
<!--asdfasdfasdf -->
        
<add key="ImageText" value="Xiao A by johnny" />
    
</appSettings>
</configuration>
private void Button1_Click(object sender, System.EventArgs e)
        
{
            
string strFileName = @"D:StudySampleCSharpAddTextToPicInitialize.xml";
            
if (System.IO.File.Exists(strFileName) == true)
            
{
                System.Xml.XmlDocument XmlDoc 
= new System.Xml.XmlDocument();                
                
                XmlDoc.Load(strFileName);

                System.Xml.XmlElement XmlEle 
= XmlDoc["configuration"];
                
if (XmlEle != null
                
{
                    XmlEle 
= XmlEle["appSettings"];
                }


                
if (XmlEle != null)
                
{
                    
foreach (System.Xml.XmlNode XmlNode in XmlEle)
                    
{
                        
if (XmlNode.Name == "add")
                        
{
                            
switch(XmlNode.Attributes.GetNamedItem("key").Value)
                            
{
                                
case "PicPath":
                                    TextBox1.Text 
= XmlNode.Attributes.GetNamedItem("value").Value + " ";
                                    
break;
                                
case "ImageText":
                                    TextBox1.Text 
= TextBox1.Text + XmlNode.Attributes.GetNamedItem("value").Value;
                                    
break;
                                
default:
                                    
break;
                            }

                        }

                    }

                }


            }

        }
發佈了31 篇原創文章 · 獲贊 0 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章