Reputation: 21
I am trying to create a very simple form that copies the contents of one directory to a USB flash drive. I have a single combo box populated with available drive letters, and a button to execute.
What I want to do (and where I am getting stuck) is to use xcopy to copy files from one static location (a networked directory) to the drive selected in the combo box.
I know this is probably pretty remedial, but hoping someone can help.
I have been trying to pass it as a variable, but am having all sorts of trouble (which is probably because I don't really know what I am doing yet.
Any suggestions for a wannabe self-taught dev?
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
cmbDrives.DataSource = Environment.GetLogicalDrives();
int num = 1;
long bigNum = num;
1 = cmbDrives.SelectedValue;
Upvotes: 0
Views: 133
Reputation: 19486
What you're looking for is the System.Diagnostics.Process
class. And you'll want to put this in the button click handler:
protected void btnGo_Click(object sender, EventArgs e)
{
string destinationDrive = cmbDrives.SelectedValue.ToString();
Process.Start("xcopy", string.Format("/someswitch {0} otherarguments", destinationDrive));
}
All that's left is to wire up the event handler. You can do this in the designer or in the Form1() constructor:
btnGo.Click += btnGo_Click;
Upvotes: 1
Reputation: 119
I think you want to show Combobox item which has "1" value on load event. If it is the case,
cmbDrives.SelectedValue="1";
Upvotes: 0
Reputation: 26209
from your comments : if you want to set the second item(index 1) as the selected item
Replace This:
1 = cmbDrives.SelectedValue;
With this:
cmbDrives.SelectedIndex = 1;
Note : Index is zero based , so you need to assign 0 to select the first Item
Upvotes: 3