本文介绍了更改在Web.config中值与一个批处理文件或.NET code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的计算机上的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");

这篇关于更改在Web.config中值与一个批处理文件或.NET code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 02:54