2
I am developing a project in c# and right now I have to select a line from a Datagridview that I created, create a text file with that data and send the created file to an ftp server. I’ve done some research, but I couldn’t find anything useful to me.If you want a code or a screenshot of my project I can make it available. This is the code of Datagridview:
SqlConnection myConnection = new SqlConnection(@"Data source = **** ; Database=**** ; User Id=****; Password=*****");
myConnection.Open();
SqlCommand objcmd = new SqlCommand("SELECT TransDocument, TransSerial, TransDocNumber, PartyName, PartyLocalityID, TotalAmount, ShipToPostalCode FROM dbo.UXMenu WHERE Estado = 0", myConnection);
objcmd.ExecuteNonQuery();
SqlDataAdapter adp = new SqlDataAdapter(objcmd);
DataTable dt = new DataTable();
adp.Fill(dt);
dataGridViewEnviarDados.DataSource = dt;
dataGridViewEnviarDados.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
UPDATE:
I’m using this code:
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://123.321.123" + arquivo.Name);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("usuario", "password");
StreamReader sourceStream = new StreamReader(arquivo.FullName);
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
MessageBox.Show("Arquivo " + arquivo.Name + " foi enviado com sucesso. " + response.StatusDescription);
response.Close();`
But I have this mistake:
Dude, FTP Server =
File Transfer Protocol
orProtocolo de Transferência de Arquivo
. There is no way you can send data to the FTP server, you can send files, what would be your real need ? what you already have ready ?– Rovann Linhalis
I’ll edit the research to explain it better. I want to select the line and write the data on that line into a text file and send that text file to ftp. I already have the whole datagridview ready just missing the part to create the text file with the selected data and send to ftp
– Josue Figueiredo