protected void ProcessFile() { btnUpload.Enabled = false; btnPreview.Enabled = false; fileReader.LoadCSV(); if (fileReader.UpdateList.Count > 0) { gvUpdateList.DataSource = fileReader.UpdateList; gvUpdateList.DataBind(); gvUpdateList.Visible = true; } if (fileReader.ErrorList.Count > 0) { gvErrorList.DataSource = fileReader.ErrorList; gvErrorList.DataBind(); gvErrorList.Visible = true; } }
static void ProcessFile(string fileType) { string fileSearch = fileType.ToUpper() + "_*"; string strftpLocation = sets.Find(x => x.SETTING_CD == "FTP_LOCATION").VALUE.ToString(); DirectoryInfo dir = new DirectoryInfo(strftpLocation); FileInfo[] files = dir.GetFiles(fileSearch).OrderByDescending(p => p.LastWriteTime).ToArray(); bool fileProcessed; if (files != null && files.Count() > 0) { byte[] buff; fileProcessed = false; foreach (FileInfo file in files) { //_file = new FileInfo(file); //_fileName = _fileName + @"<br/>" + _file.Name; buff = File.ReadAllBytes(file.FullName); fileReader = new SQMFileReader().InitializeCSV(primaryCompany, file.Name, buff, fileDelimiter, plantDataMultiplier, 0, 0, "USD"); if (fileReader.Status < 0) { WriteLine("Error encountered loading the file: " + file); } else { if (!fileProcessed) // only process the most recent file { fileReader.FileName = fileType.ToUpper(); fileReader.LoadCSV(); fileProcessed = true; WriteLine(file.Name + " processed " + DateTime.UtcNow.ToString("hh:mm MM/dd/yyyy")); } // move the file string sourceFile = file.FullName; string destinationFile = strftpLocation + @"\Processed\" + file.Name; System.IO.File.Move(sourceFile, destinationFile); } } } }
static void ProcessFile(string fileType) { fileReader.LoadCSV(); if (fileReader.UpdateList.Count > 0) { WriteLine(fileReader.FileName + " records processed: " + fileReader.UpdateList.Count.ToString()); // no need to write these out to a file } if (fileReader.ErrorList.Count > 0) { WriteLine(fileReader.FileName + " records with errors: " + fileReader.ErrorList.Count.ToString()); // we need to create an error file... StringBuilder dataFile = new StringBuilder(); for (int i = 0; i < fileReader.ErrorList.Count; i++) { WriteLine("Line: " + fileReader.ErrorList[i].LineNo + "; Node: " + fileReader.ErrorList[i].Node + "; Message: " + fileReader.ErrorList[i].Message); dataFile.AppendLine(fileReader.ErrorList[i].DataLine); } string fullPath = fileLocation + fileType + "_ERRORS_" + timestamp + ".txt"; File.WriteAllText(fullPath, dataFile.ToString()); } }