更改在Web.config中值与一个批处理文件或.NET code中值、批处理文件、config、Web

2023-09-05 00:33:13 作者:不致太寡

我有我的计算机上的web.config文件。

I have a web.config file on my computer.

有很多的事情,我需要改变,并添加到文件中。 (其实我的工作与我的SharePoint web.config文件)的

There are alot of things i need to change and add in the file. (I am actually working with my SharePoint web.config file)

我能做到这一点有一个批处理文件,如果是的话我会怎么做它。 或者,会怎么办使用VB.NET或C#code呢?

Can i do this with a Batch file, if so how would i do it. Or how would i do it using VB.NET or C# code?

任何想法家伙?

编辑:我需要创建一个程序来改变一个web.config可以说我的web.config铺设在我的deskop和我的项目不实际的web.config

i need to create a program to alter a web.config of lets say i web.config laying on my deskop and not the actual web.config of my project

问候 艾蒂安

推荐答案

这就是我需要做的.......感谢所有帮助!

This is what i needed to do.......thanks for all the help!!!

// Read in Xml-file 
        XmlDocument doc = new XmlDocument();
        doc.Load("C:/Web.config");

        //SaveControl tag..........................................................
        XmlNode n = doc.SelectSingleNode("/configuration/SharePoint/SafeControls");

        XmlElement elemWeb = doc.CreateElement("SafeControl");
        elemWeb.SetAttribute("Assembly", "SamrasWebOption4");
        elemWeb.SetAttribute("Namespace", "SamrasWebOption4");
        elemWeb.SetAttribute("TypeName", "*");
        elemWeb.SetAttribute("Safe", "True");

        XmlElement elemSmartPart = doc.CreateElement("SafeControl");
        elemSmartPart.SetAttribute("Assembly", "Machine_Totals");
        elemSmartPart.SetAttribute("Namespace", "Machine_Totals");
        elemSmartPart.SetAttribute("TypeName", "*");
        elemSmartPart.SetAttribute("Safe", "True");

        //Appending the Nodes......................................................
        n.AppendChild(elemWeb);
        n.AppendChild(elemSmartPart);

        //Saving the document......................................................
        doc.Save("C:/Web.config");