Here is my code. I want to export/upload this .dat
file into zip format to the FTP server.
I try a lot but not find any solution. anyone can help me with this problem.
public string ExportVoid(FileSetups fileSetup, HttpPostedFileBase file)
{
var sb = new System.Text.StringBuilder();
var list = _context.VOIDS.ToList();
foreach (var item in list)
{
sb.AppendFormat("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\r", item.Date, item.Time, item.Shift, item.EmployeeID, item.Amount, item.Items, item.DrawerOpen, item.Postpone, item.LocationID);
}
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
WebClient myWebClient = new WebClient();
var dbftp = _context.FileSetup.SingleOrDefault();
var a = dbftp.FTP;
var v = Session["ClientId"];
var d = DateTime.Now.ToString("MM_dd_yyyy_hh:mm:ss");
string uriString = "ftp://MyFTP.com/Files/" + "Void" + ".dat";
myWebClient.Credentials = new NetworkCredential("userName", "password");
//Console.WriteLine("\nPlease enter the data to be posted to the URI {0}:", uriString);
string postData = sb.ToString();
// Apply ASCII Encoding to obtain the string as a byte array.
byte[] postArray = Encoding.ASCII.GetBytes(postData);
myWebClient.Headers.Add("Content-Disposition", "attachment; filename=" + "Void.dat");
byte[] responseArray = myWebClient.UploadData(uriString, postArray);
return "Export Successfully!";
}