Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9076867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:12:11+00:00 2026-06-16T19:12:11+00:00

I have such code so far: private void button3_Click(object sender, EventArgs e) { label1.Visible

  • 0

I have such code so far:

private void button3_Click(object sender, EventArgs e)
{
    label1.Visible = true;
    label2.Visible = true;
    var items = File.ReadAllLines("updated database folder/Resellers_Inventory.txt").
    Skip(1).
    Select(s =>
    {
        var strings = s.Split('|');
        if (strings.Length != 2) throw new FormatException();
        return new { Code = strings[0], Stock = Convert.ToInt32(strings[1]) };
    }).
    ToArray();

    var compareTo = File.ReadAllLines("old database folder/ProductAll.txt").
                Skip(1).
                Select(s =>
                {
                    var strings = s.Split(',');
                    if (strings.Length != 6) throw new FormatException();
                    return new { Path = strings[2].Trim('"'), Id = Convert.ToInt32(strings[3]), Name = strings[4].Trim('"'), Code = strings[5].Trim('"'), Stock = Convert.ToInt32(strings[6]) };
                }).
                ToArray();

    string foldername = DateTime.Now.ToString("yyyy--MM--dd");
    Directory.CreateDirectory("Update file of " + foldername);
    string UpdeitoFailas = @"Update file of " + foldername + "/update.txt";

    foreach (var item in items.Where(i => compareTo.Any(i2 => i.Code == i2.Code)))
    {
        if ((File.Exists(UpdeitoFailas)) && i.Stock != i2.Stock)
        {
            using (StreamWriter sw = new StreamWriter(UpdeitoFailas))
            {
                sw.Write("Product, " + i2.Path + ", " + i2.Id + ", " + i2.Name + ", " + i2.Code + ", " + i.Stock);
             }
         }
     }

The file “Resellers_Inventory.txt” is like this (and consists hundreds of thousands lines):

Order Code|Stock
ACREPAIR|1031
AF813|18
AF823|12
AFCOB11|21
AFCS300|33
AFCS3000|1
AFEM4|5
AFOMNI|17
AFOX2|-3
AFOX3|-3
AFROD|28
AFSENSOR|50
AFUF21|24
AN00001|-1
AN00002|21
AN00003|4
AN00004|4
AN00005|9
...

ProductAll.txt file also consists hundreds of thousands lines which looks like these:

Action,CategoryPath,ID,Name,Code,Stock
"Product","Home > Opto-electronics > LED > Standard LED, Multicolour",2226,"KINGBRIGHT LED, 3MM, HE-RED/GRN L-93WEGW","SC07621",202
"Product","Home > Resistors > Fixed",2228,"VISHAY DRALORIC RESISTOR, 0402, 5%, 10K0 CRCW040210K0JNEAIF","RE06211",0
"Product","Home > Resistors > Fixed",2229,"VISHAY DRALORIC RESISTOR, 0402, 5%, 3R90 CRCW04023R90JNEAIF","RE06212",0
"Product","Home > Resistors > Fixed",2230,"VISHAY DRALORIC RESISTOR, 0402, 5%, 2R70 CRCW04022R70JNEAIF","RE06220",25
"Product","Home > Resistors > Fixed",2231,"VISHAY DRALORIC RESISTOR, 0402, 5%, 33R0 CRCW040233R0JNEAIF","RE06221",0
"Product","Home > Resistors > Fixed",2232,"VISHAY DRALORIC RESISTOR, 0402, 5%, 100R CRCW0402100RJNEAIF","RE06226",0
"Product","Home > IC's > Comparators",2234,"STMICROELECTRONICS IC, COMPARATOR DUAL, DIP8, 393 LM393N","SC10207",57
"Product","Home > IC's > Amplifiers > Operational",2237,"STMICROELECTRONICS OP AMP, QUAD JFET, DIP14 TL084CN","SC07929",82
"Product","Home > IC's > Amplifiers > Audio Power",2239,"NATIONAL SEMICONDUCTOR AMP, AUDIO 0.25W, DIP8, 386 LM386N-1","SC08430",83
"Product","Home > IC's > Microcontrollers",2241,"MICROCHIP 8BIT FLASH MCU, 12F675, DIP8 PIC12F675-I/P","ACREPAIR",16
...

Basically what I want to do is to create third file which would look like ProductAll.txt, but would be different in such way: if in Resellers_Inventory.txt stock is different from ProductAll.txt then we write a line to update.txt which looks same as line in ProductAll.txt but with stock value from Resellers_Inventory.txt. If stock values are same we skip this line and don’t write to our new third file. Matching lines (stocks) is implemented by matching item codes which are same in both files.

At the moment I’m getting such errors:

Error   1   The name 'i' does not exist in the current context  C:\Users\Tutis\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 90  53  WindowsFormsApplication1
Error   2   The name 'i2' does not exist in the current context C:\Users\Tutis\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 90  64  WindowsFormsApplication1
Error   3   The name 'i2' does not exist in the current context C:\Users\Tutis\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 94  48  WindowsFormsApplication1
Error   4   The name 'i2' does not exist in the current context C:\Users\Tutis\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 94  65  WindowsFormsApplication1
Error   5   The name 'i2' does not exist in the current context C:\Users\Tutis\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 94  80  WindowsFormsApplication1
Error   6   The name 'i2' does not exist in the current context C:\Users\Tutis\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 94  97  WindowsFormsApplication1
Error   7   The name 'i' does not exist in the current context  C:\Users\Tutis\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 94  114 WindowsFormsApplication1

But even without this I don’t know how to write to new update.txt file symbols “ that lines would look same as in ProductAll.txt just with other stock value.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:12:13+00:00Added an answer on June 16, 2026 at 7:12 pm

    Its a bit hard to see whats going on in the code, but you can use File.WriteAllLines to create your results file.

    I’m using my answer from your question yesterday to show it working as i can’t get the example you posted working.

        private void UpdateProducts()
        {
            ThreadPool.QueueUserWorkItem((o) =>
            {
                DateTime start = DateTime.Now;
                List<string> updatedProducts = new List<string>();
                List<string[]> stock = new List<string[]>(File.ReadAllLines("G:\\Stock.txt").Select(line => line.Split('|')));
                List<string> products = new List<string>(File.ReadAllLines("G:\\Products.txt"));
                updatedProducts.Add(products[0]);
                SetProgress(products.Count);
                foreach (var item in products)
                {
                    if (stock.Any(s => item.Contains(s[0]) && !item.EndsWith(s[1])))
                    {
                        string[] p = item.Split(',');
                        int productStockIndex = Array.IndexOf(p, p.Last());
                        int productNameIndex = productStockIndex - 1;
                        string productName = p[productNameIndex].Replace("\"", "");
                        p[productStockIndex] = stock.First(stk => stk[0] == productName)[1];
                        updatedProducts.Add(string.Join(",", p));
                    }
                    UpdateProgress(updatedProducts.Count);
                }
                File.WriteAllLines(@"G:\Results.txt", updatedProducts.ToArray());
            });
        }
    
        private void SetProgress(int maxValue)
        {
            base.Invoke((Action)delegate 
            {
                progressBar1.Maximum = maxValue;
            });
        }
    
        private void UpdateProgress(int value)
        {
            base.Invoke((Action)delegate
            {
                progressBar1.Value = value;
            });
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
            UpdateProducts();
        }
    

    good luck 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have such code var prj = _dataContext.Project.FirstOrDefault(p => p.isPopular == true); if (prj
I have such code in my JSF template: <h:form> <table id=users cellspacing=0> <a4j:repeat var=person
i have such code (copy paste from wiki). Its multiplication of those big numbers
I have such code: $updateSQL = UPDATE `Rooms` R SET R.Revenue = {$s['Revenue']}, R.Ave_rent
I have such code: <h:inputText id=input value=#{bean.input}> <f:convertNumber /> <rich:ajaxValidator event=onblur /> </h:inputText> I
I have such code: function allValid() { $('input').each(function(index) { if(something) { return false; }
I have such code: Prelude> let n = [1,2,3,4] Prelude> n [1,2,3,4] Prelude> 0:n
I'm trying to understand how php function usort works. I have such code: <?php
I have a such code for Lithuanian declension: <?php $word = namas; $string =
Let's say I have such PoC code snippet for working with canvas raw pixel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.