good day everyone!

i have a problem...

i have 27 text files in a folder named dito... and every minute there will be new text file in a folder...

i need to create a program that saves a record locator(9-digit-code)...

the rule is that there will be no human interactions..

once the program is opened,,, it will automatically open the text files one by one in the folder named dito and save the 9-digit-code(record locator) which is located in line 4 beside MUC1A(note: this is a consistent data... all of the text files that will go in the folder will contain this MUC1A data..)

then it will automatically save the 9-digit-code in the database and move the textfile to another folder name trash and delete its copy in the folder named dito...

it should be a continues process that will not stop unless the folder named dito will no longer receive a textfile

who can help me? please my deadline is tomorrow and i'm new in c sharp programming and in using asp.net 3.5 windows application

here's the code that i started but it's not yet finish

my code just open a single textfile and show the 9 digit code in a label1.text

using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ftl.DataSet1TableAdapters;



namespace ftl
{
    public partial class Form1 : Form
    {
        ReLocTableAdapter rs = new ReLocTableAdapter();
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string file_name = "C:\\dito\\AIR41391.txt";

            if (System.IO.File.Exists(file_name) == true)
            {

                System.IO.StreamReader objReader;
                objReader = new System.IO.StreamReader(file_name);

                textBox1.Text = objReader.ReadToEnd();

                objReader.Close();
            }

            string str = textBox1.Text;
            string retString = "MUC1A";
            str = textBox1.Text;
            retString = str.Substring(111,9);
            label1.Text= retString;
            


            rs.InsertQuery(label1.Text);

        }

        }

        
    }

Dani AI

Generated

A few focused, practical notes to make this unattended extractor reliable. : reading the whole file into a textbox and using Substring(111,9) is brittle (layout can shift) and will block the UI. is right to point toward folder watching — but combine an initial directory scan with a FileSystemWatcher, process each file on a background thread, and only move the file to a trash folder after a successful, transactional DB insert.

A minimal, robust way to get the 4th line and pull the 9-digit code next to MUC1A (works with .NET 3.5+) is to read only the lines you need and use a regex to find the 9 digits:

using System.IO;
using System.Text.RegularExpressions;

string ExtractRecordLocator(string path)
{
    using (var r = new StreamReader(path))
    {
        string line = null;
        for (int i = 0; i < 4; i++)
        {
            line = r.ReadLine();
            if (line == null) return null;
        }
        var m = Regex.Match(line, @"MUC1A\D*?(\d{9})");
        return m.Success ? m.Groups[1].Value : null;
    }
}

Operational tips and cautions:

  • On startup, process any existing files then start a FileSystemWatcher for Created/Renamed events. Debounce events: files are often written slowly, so wait until the file can be opened exclusively or its size is stable for a short interval before processing.
  • Do DB insert inside a transaction and only call File.Move to the trash folder after the insert succeeds; on failure move to an error folder and log the problem.
  • Run processing on a worker thread (Task/BackgroundWorker) so the UI stays responsive.
  • Make paths configurable (app.config), handle encodings explicitly if needed, and add a unique constraint or dedup-check in the DB to avoid double inserts.

These steps will make the service resilient to partial writes, layout variation, and transient errors while matching the automated workflow you described.

1. You should be using FileSystemWatcher to wait for files.
2. Since your requirement is to read a text file line by line, you can use StringReader, using which you can read a file line by line.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.