Click here to Skip to main content
15,909,466 members
Home / Discussions / C#
   

C#

 
GeneralRe: Method for erase textboxes by clicking a button Pin
Vexy28-May-14 8:36
Vexy28-May-14 8:36 
GeneralRe: Method for erase textboxes by clicking a button Pin
Eddy Vluggen28-May-14 9:18
professionalEddy Vluggen28-May-14 9:18 
AnswerRe: Method for erase textboxes by clicking a button Pin
osamashatnawe29-May-14 0:27
osamashatnawe29-May-14 0:27 
QuestionHow to find interfaces in code programmatically Pin
Frygreen28-May-14 6:31
Frygreen28-May-14 6:31 
AnswerRe: How to find interfaces in code programmatically Pin
Richard MacCutchan28-May-14 6:40
mveRichard MacCutchan28-May-14 6:40 
AnswerRe: How to find interfaces in code programmatically Pin
Kornfeld Eliyahu Peter28-May-14 6:41
professionalKornfeld Eliyahu Peter28-May-14 6:41 
AnswerRe: How to find interfaces in code programmatically Pin
Eddy Vluggen28-May-14 7:21
professionalEddy Vluggen28-May-14 7:21 
AnswerRe: How to find interfaces in code programmatically Pin
jschell28-May-14 8:46
jschell28-May-14 8:46 
AnswerRe: How to find interfaces in code programmatically Pin
BobJanova29-May-14 1:20
BobJanova29-May-14 1:20 
QuestionLoading and unloading assemblies using reflection Pin
nitin_ion28-May-14 1:38
nitin_ion28-May-14 1:38 
SuggestionRe: Loading and unloading assemblies using reflection Pin
Richard MacCutchan28-May-14 2:46
mveRichard MacCutchan28-May-14 2:46 
AnswerRe: Loading and unloading assemblies using reflection Pin
Rob Philpott28-May-14 4:52
Rob Philpott28-May-14 4:52 
QuestionInserting missing attributes in XML / app.config file Pin
Flockston8627-May-14 22:59
Flockston8627-May-14 22:59 
Hi,

I wrote an application that is running on multiple systems (>50). As this application gets new features frequently, I want to write a Launcher that is updating the program.
Exchanging the exe file is not a problem, but it get in trouble when the config file of the application changes.

The app.config file is divided into multiple configSections depending on its platform. I use a CustomSection as well, so the config file looks like this:

XML
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="Section1" type="App.CustomSection,App"/>
    <section name="Section2" type="App.CustomSection,App"/>
  </configSections>

  <Section1
    Attrib1="true"
    Attrib2="true"
    .
    .
    .
    AttribN="Value"
    />

  <Section2
    Attrib1="true"
    Attrib2="true"
    .
    .
    .
    AttribN="Value"
    />
  
</configuration>


Now the launcher shall detect new attributes (comparing to a file at a file server), and insert them at the correct position (e.g. if an attribute Attrib1.5 is added, between Attrib1 and Attrib2).

The already present attribute values shall not be changed, but remain at their machine specific configuration.

I tried to solve this with the System.Xml namespace, but as I'm not very familiar with it, I was not able to solve my problem.

I also tried a Streamreader. This works partly, but if there are some blank lines on the machine, this does not work and if the order of the attributes has been changed, neither.

Here the code snippet:

C#
private bool syncConfigFiles(string serverConfigFile, string localConfigFile)
        {
            List<string> _serverFileContent = FileHandler.getFileContent(serverConfigFile);
            List<string> _localFileContent = FileHandler.getFileContent(localConfigFile);

            for (int i = 0; i < _serverFileContent.Count; i++)
            {
                
                if (_serverFileContent[i].Trim() != _localFileContent[i].Trim())
                {
                    string _checkStringServer = _serverFileContent[i].Trim();
                    string _checkStringLocal = _localFileContent[i].Trim();
                    if (_checkStringServer.Contains("=") && _checkStringLocal.Contains("="))
                    {
                        _checkStringServer = _checkStringServer.Substring(0, _checkStringServer.IndexOf("="));
                        _checkStringLocal = _checkStringLocal.Substring(0, _checkStringLocal.IndexOf("="));
                    }
                    if (_checkStringServer != _checkStringLocal)
                    {
                        _localFileContent.Insert(i, _serverFileContent[i]);
                    }
                }
            }
            FileHandler.writeLines(localConfigFile, _localFileContent, false);
            return true;
        }


I already googled some hours and used this forum search, but no success.

Can you help me?

Thanks in advance,

Flockston
AnswerRe: Inserting missing attributes in XML / app.config file Pin
Dave Kreskowiak28-May-14 2:29
mveDave Kreskowiak28-May-14 2:29 
AnswerRe: Inserting missing attributes in XML / app.config file Pin
Flockston863-Jun-14 1:20
Flockston863-Jun-14 1:20 
GeneralRe: Inserting missing attributes in XML / app.config file Pin
Dave Kreskowiak3-Jun-14 2:14
mveDave Kreskowiak3-Jun-14 2:14 
GeneralRe: Inserting missing attributes in XML / app.config file Pin
Flockston863-Jun-14 2:25
Flockston863-Jun-14 2:25 
GeneralRe: Inserting missing attributes in XML / app.config file Pin
Dave Kreskowiak3-Jun-14 4:42
mveDave Kreskowiak3-Jun-14 4:42 
QuestionVisual Studio Output to Run as Admin always Pin
Subin Mavunkal27-May-14 22:57
Subin Mavunkal27-May-14 22:57 
AnswerRe: Visual Studio Output to Run as Admin always Pin
Richard MacCutchan28-May-14 0:53
mveRichard MacCutchan28-May-14 0:53 
Questioncustom file properties Pin
jeffingeorge27-May-14 22:38
jeffingeorge27-May-14 22:38 
AnswerRe: custom file properties Pin
Chris Quinn27-May-14 22:48
Chris Quinn27-May-14 22:48 
AnswerRe: custom file properties Pin
Eddy Vluggen28-May-14 0:28
professionalEddy Vluggen28-May-14 0:28 
QuestionFile opertions Pin
jeffingeorge27-May-14 22:36
jeffingeorge27-May-14 22:36 
AnswerRe: File opertions Pin
Karen Mitchelle27-May-14 22:51
professionalKaren Mitchelle27-May-14 22:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.