Link to home
Start Free TrialLog in
Avatar of Daniel_P67
Daniel_P67

asked on

Split Commandline Arguments/parameters Into Variables

Stuck on a bit of code. We are calling a program with parameters, Example: program.exe \\server\file nameoffile pdf status. Want to take each parameter separated by a space and assign it to a string variable. On this line  "string[] words = args.Split(' ');", "args" is giving me the error system.array has no definition for Split. Have not been able to get past this point.

Any help or comments are welcomed!


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Programname : Form
    {
        
       
        string[] args = Environment.GetCommandLineArgs();
    
              
        public Programname()
        {
            InitializeComponent();
        }

       
        private void OpenDrawing_Click(object sender, EventArgs e)
        {


            string[] words = args.Split(' ');

            string docPath = words[0];
            string docFile = words[1];
            string docExt = words[2];
            string docType = words[3];
            string docStatus = words[4];

}
}
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Daniel_P67
Daniel_P67

ASKER

Great thanks!!! Checked with the below code. Placed a quick text box and pasted in the info out of order, worked just like i wanted.


  
//string[] words = args.Split(' '); //deleted

            string docPath = args[0];
            string docFile = args[1];
            string docExt = args[2];
            string docType = args[3];
            string docStatus = args[4];


            textBox1.Text = docPath + docExt + docFile;

Open in new window

Explanation was good enough to help me solve the issue. Thanks!