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 8434637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:42:41+00:00 2026-06-10T06:42:41+00:00

I have developed a windows application, which will read updated data from .jrn files(In

  • 0

I have developed a windows application, which will read updated data from .jrn files(In an ATM Machine) and will be copy the text to a temporary text file “tempfile.txt”.

There is another third party application called “POS Text Sender”, which reads “tempfile.txt” and display the contents of it in a CCTV Camera.

The problem is that if I type directly something in the tempfile, the POS application will read it, but if my application writes text to “tempfile”, I can see the same content as in the .jrn file in tempfile, but it is not reflected in the POS application when ever data is copied from newly generated file to tempfile.if restart the POS Text Sender after the first data copied to tempfile from newly generated file,POS Text sender will display the content til content from newly created file is written to tempfile

My application code is reading .jrn file using StreamReader and assigning it to a string variable and then writing it to a tempfile using StreamWriter. What is the difference between manually typing text on a file and .NET StreamWriter writing text to a file?

CODE:

 DateTime LastChecked = DateTime.Now;
 try
 {
     string[] files = System.IO.Directory.GetFiles(@"C:\Test", "*.jrn", System.IO.SearchOption.AllDirectories);

     foreach (string file in files)
     {
         if (!fileList.Contains(file))
         {
             currentfilename = file;
             fileList.Add(file);
             copywarehouse(file);
             //do_some_processing();
             try
             {
                 // Create an instance of StreamReader to read from a file.
                 // The using statement also closes the StreamReader.
                 using (StreamReader sr = new StreamReader(file))
                 {
                     currentcontent=sr.ReadToEnd();
                     // Read and display lines from the file until the end of
                     //// the file is reached.
                     //while ((currentcontent = sr.ReadLine()) != null)
                     //{

                     //}
                     sr.Close();
                     //sr.Dispose();
                 }
             }
             catch (Exception)
             {
                 // Let the user know what went wrong.

             }
         }
     }

     //checking
     try
     {
         using (StreamReader sr = new StreamReader(currentfilename))
         {
             string currentfilecontent = sr.ReadToEnd();
             sr.Close();
             //sr.Dispose();
             if (currentfilecontent!=currentcontent)
             {
                 if (currentfilecontent.Contains(currentcontent))
                 {
                     string originalcontent = currentfilecontent.Substring(currentcontent.Length);
                     System.IO.StreamWriter filenew = new System.IO.StreamWriter(@"C:\Test\tempfile.txt");

                     filenew.WriteLine(originalcontent);
                     filenew.Close();
                     currentcontent = currentfilecontent;
                 }
             }
         }
     }
     catch (Exception)
     {
         // Let the user know what went wrong.
     }

copywarehouse method:

 private void copywarehouse(string filename)
 {
    string sourcePath = @"C:\Test";
    string targetPath = @"C:\Test";
    try
    {
       string sourceFile = System.IO.Path.Combine(sourcePath, filename);
       string destFile = System.IO.Path.Combine(targetPath, "tempfile.txt");
       System.IO.File.Copy(sourceFile, destFile, true);
    }
    catch (Exception)
    {

    }
}
  • 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-10T06:42:42+00:00Added an answer on June 10, 2026 at 6:42 am

    Can you check the following:

    1. Is the generated file encoding same as the manually created file? (i.e. UTF-8/ANSI).
    2. Are your constantly flushing the streamWriter’s buffer? Or set the StreamWriter’s AutoFlush property to true.
    3. Is the StreamWriter opened with a WriteLock with no read allowed? In this case the other application may not be able to open your tempfile for read access.

    EDIT:

    Also, in the code you posted, you are comparing the tempFile data to current data, and if tempFile data is newer than current data, you are appending the temp file, which I think should be vice versa.

    Main change:

    using (StreamWriter filenew = new StreamWriter(fileDetail.TempFileName, true, Encoding.ASCII))
                                    {
                                        filenew.WriteLine(newContent);
                                    }
    

    To know the correct encoding, just create a new tempFile, write something in the editor and save it. Open the file in notepad and do a “save as”. This will display the current encoding in the bottom. Set that encoding in .NET code.

    If this does not work try (As recommended by shr):

    using (StreamWriter filenew = new StreamWriter(fileDetail.TempFileName, true, Encoding.ASCII))
                                    {
                                        filenew.Write(newContent + "\r\n");
                                    }
    

    Long Version: (It may be a bit different than your code):

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                DateTime LastChecked = DateTime.Now;
    
                IDictionary<string, FileDetails> fileDetails = new Dictionary<string, FileDetails>(StringComparer.OrdinalIgnoreCase);
                IList<string> tempFileList = new List<string>();
    
                try
                {
                    string[] files = System.IO.Directory.GetFiles(@"C:\Test", "*.jrn", System.IO.SearchOption.AllDirectories);
    
                    foreach (string file in files)
                    {
                        string currentfilename = file;
                        string currentcontent = string.Empty;
    
                        if (!fileDetails.Keys.Contains(file))
                        {
                            fileDetails[file] = new FileDetails(copywarehouse(file));
                            //do_some_processing();
                        }
    
                        try
                        {
                            using (StreamReader sr = new StreamReader(file))
                            {
                                currentcontent = sr.ReadToEnd();
                            }
                        }
                        catch (Exception)
                        {
                            // Let the user know what went wrong.
                        }
    
                        fileDetails[file].AddContent(currentcontent);
                    }
    
                    //TODO: Check using the file modified time. Avoids unnecessary reading of file.
                    foreach (var fileDetail in fileDetails.Values)
                    {
                        //checking
                        try
                        {
                            string tempFileContent = string.Empty;
                            string currentcontent = fileDetail.GetContent();
    
                            using (StreamReader sr = new StreamReader(fileDetail.TempFileName))
                            {
                                tempFileContent = sr.ReadToEnd();
                                sr.Close();
                            }
    
                            if (!(0 == string.Compare(tempFileContent, currentcontent)))
                            {
                                if (currentcontent.Contains(tempFileContent))
                                {
                                    string newContent = tempFileContent.Substring(currentcontent.Length);
    
                                    using (StreamWriter filenew = new StreamWriter(fileDetail.TempFileName, true, Encoding.ASCII))
                                    {
                                        filenew.WriteLine(newContent);
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        {
                            // Let the user know what went wrong.
                        }
    
                    }
                }
                catch (Exception)
                {
                }
            }
    
            private static string copywarehouse(string filename)
            {
                string sourcePath = @"C:\Test";
                string targetPath = @"C:\Test";
    
                string sourceFile = System.IO.Path.Combine(sourcePath, filename);
                string destFile = System.IO.Path.Combine(targetPath, filename+ "tempfile.txt");
    
                try
                {
                    System.IO.File.Copy(sourceFile, destFile, true);
                }
                catch (Exception)
                {
                }
    
                return destFile;
            }
    
            internal class FileDetails
            {
                public string TempFileName { get; private set; }
                private StringBuilder _content;
    
                public FileDetails(string tempFileName)
                {
                    TempFileName = tempFileName;
                    _content = new StringBuilder();
                }
    
                public void AddContent(string content)
                {
                    _content.Append(content);
                }
    
                public string GetContent()
                {
                    return _content.ToString();
                }
            }
        }
    }
    

    EDIT 2:
    Can you change the copywarehouse to this and see it the problem persists:

             private void copywarehouse(string filename)
            {
                const string sourcePath = @"C:\Test";
                const string targetPath = @"C:\Test";
                try
                {
                    string sourceFile = Path.Combine(sourcePath, filename);
                    string destFile = Path.Combine(targetPath, "tempfile.txt");
    
    
                    string currentcontent;
                    using (var sr = new StreamReader(sourceFile))
                    {
                        currentcontent = sr.ReadToEnd();
                    }
    
                    using (var wr = new StreamWriter(destFile, false, Encoding.ASCII))
                    {
                        wr.WriteLine(currentcontent);
                    }
                }
                catch (Exception)
                {
    
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a windows service which reads data from a database, the database
I have an application which was developed under Windows, but for gcc. The code
I have developed an embedded application which requests status information from a device down
I have developed one application which will have activities and one background service and
I have developed a windows application with vs2010 and c#. I would like to
I have developed a windows forms c# application, i just want update items in
I have developed a application for a client who uses windows 7 home premium
I have an application developed in C++ in Visual Studio 2003 (Windows Forms application).
On Windows 7, VB.NET Express, I have developed a simple Forms application. I don't
does anyone have an idea or developed before windows authentication through flex application. I

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.