?
Solved

Reading XML and running an external application

Posted on 2006-06-05
5
Medium Priority
?
194 Views
Last Modified: 2012-05-05
Hi guys,

I am looking to make an autorun application with C#, now I basically just need to know how to do two things...

1/ How to read an XML file (filenames)
2/ How to run external applications (setup files)

If someone could give me the rough code I need, I can then edit it to do what I want.

Cheers!
0
Comment
Question by:Cyber-Drugs
  • 3
  • 2
5 Comments
 
LVL 12

Expert Comment

by:gbzhhu
ID: 16831911

Q 2

System.Diagnostics.Process.Start(@"path to your setup.exe goes here");  
will run extenal file

If you want to control window state of the started process then you will have to create a processinfo object and set it up as you want then pass that to the start method above instead of the path

Q1 .... code posted next while you digest answer to Q2
0
 
LVL 12

Accepted Solution

by:
gbzhhu earned 2000 total points
ID: 16831943
For Q2

You normally to save your program objects to xml files then read them back at some point later.  I am giving you an example like that so you can modify it to fit to your solution.  In this example I have a class called userInfo which holds username and password

        public static UserInfo Load()
        {
            UserInfo loaded = new UserInfo();
            StreamReader file = null;

            try
            {
                XmlSerializer reader = new XmlSerializer(loaded.GetType());
                // Read the XML file.
                file = new StreamReader(Common.UserDataPath + "bpc_UserInfo.Xml");
                // Deserialise the object.
                loaded = (UserInfo)reader.Deserialize(file);
            }
            catch (Exception ex)
            {
                ExceptionManager exception = new ExceptionManager();       //this our own implementation of exceptionmanager so you want to replace this with your own exception handliong code
                exception.LogException(ex);
            }
            finally
            {
                if (file != null)
                {
                    file.Close();
                }            
            }

            return loaded;
        }
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 16832010
Thanks for the quick response, just a quick question...

What structure is the XML for your example?

Cheers!
0
 
LVL 12

Expert Comment

by:gbzhhu
ID: 16832238
This is the XML file

<?xml version="1.0" encoding="utf-8"?>
<UserInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Username>foo.fooSurname@server.co.uk</Username>
  <Password>password</Password>
</UserInfo>
0
 
LVL 4

Author Comment

by:Cyber-Drugs
ID: 16933102
Sorry, I forgot all about this code!!

Works perfectly, cheers! :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Screencast - Getting to Know the Pipeline
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question