0

I have four columns and I've added a checkbox column to a DataGridView in my C# form. I have got the selected row values also as below:

private void button3_Click(object sender, EventArgs e)
    {
    List<DataGridViewRow> rows_with_checked_column = new List<DataGridViewRow>();
        foreach (DataGridViewRow row in dataGridView1.Rows)
        {
            if (Convert.ToBoolean(row.Cells[dataGridView1.Columns[1].Name].Value) == true)
            {
                rows_with_checked_column.Add(row);
            }
    }

Below is the code that I have for FTP

string ftpfullpath = @"ftp://" + IPAddress + "/C:/ADX_IPGM/SVIBM.JAR";
string ftpusername = "stcprc";
string ftppassword = "pos9$2";
string source = "d:\ftp.txt";
textBox1.AppendText(System.Environment.NewLine + "Connecting to Controller " + rows_with_checked_column);
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
ftp.Credentials = new NetworkCredential(ftpusername, ftppassword);
textBox1.AppendText(System.Environment.NewLine + "User " + ftpusername + " Logged in to Controller " + rows_with_checked_column);

ftp.KeepAlive = true;
ftp.UseBinary = true;
ftp.Method = WebRequestMethods.Ftp.UploadFile;

FileStream fs = File.OpenRead(source);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();

Stream ftpstream = ftp.GetRequestStream();
ftpstream.Write(buffer, 0, buffer.Length);
ftpstream.Close();
success_count += 1;
label1.Text = "Successful Transfers (" + success_count + ")";
textBox1.AppendText(System.Environment.NewLine + "File Transferred successfully!");

Next I need help to loop it with the selected rows by referring the IP address column "URL".

Denesh Kumar
  • 95
  • 1
  • 10
  • What does your data binding look like? Each DataGridViewRow should have a DataBoundItem property that you can cast to the type that is bound to the grid. Is the IP address in the bound object? – SteveR Nov 21 '16 at 13:01
  • Yes, Column name is "URL" – Denesh Kumar Nov 21 '16 at 13:16
  • Then you should be able to do something like ((YourClass)row.DataBoundItem).URL – SteveR Nov 21 '16 at 13:18
  • I need the value of "URL" column in a string variable from 'rows_with_checked_column' to append it in FTP request, pls suggest an example – Denesh Kumar Nov 21 '16 at 13:24
  • foreach(var row in rows_with_checked_column){ string url = ((YourClass)row.DataBoundItem).URL;} – SteveR Nov 21 '16 at 13:29

0 Answers0