Asp.Net 常用代码-备用

1、发邮件


    }

2、读写AppConfig.config

/// <summary>

    /// 设置AppConfig配置文件

    /// </summary>

    /// <param name="AppKey">键</param>

    /// <param name="AppValue">值</param>

    public  void SetValue(string AppKey, string AppValue)

    {

        XmlDocument xDoc = new XmlDocument();

        //string path = Application.ExecutablePath;

        ServerInfo.GetRootPath();

        //path = path.Remove(path.IndexOf("bin"));

        //xDoc.Load(path + "App.config");

        string path = Server.MapPath("~/");

        xDoc.Load(path + "AppConfig.config");



        XmlNode xNode;

        XmlElement xElem1;

        XmlElement xElem2;

        // xNode = xDoc.SelectSingleNode("//configuration");

        xNode = xDoc.SelectSingleNode("//appSettings");

        xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");

        if (xElem1 != null)

        {

            xElem1.SetAttribute("value", AppValue);

        }

        else

        {

            xElem2 = xDoc.CreateElement("add");

            xElem2.SetAttribute("key", AppKey);

            xElem2.SetAttribute("value", AppValue);

            xNode.AppendChild(xElem2);

        }

        xDoc.Save(path + "AppConfig.config");

    }

  

 3、webform获取实际地址:

 string strFilePath = Server.MapPath("~//ExamRecord.xml");

 

  

 

你可能感兴趣的:(asp.net)