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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:02:37+00:00 2026-06-05T17:02:37+00:00

I am working with Visual Studio 2008 to write a C# utility to merge

  • 0

I am working with Visual Studio 2008 to write a C# utility to merge database script for release.

Here is what the code looks like

strPath = txtInputFolder.Text;

DirectoryInfo di = new DirectoryInfo(strPath);
FileInfo[] lstFile = di.GetFiles("*.sql");

string strScriptPath = System.IO.Path.Combine(strPath, lblOutput.Text);
FileStream foutput = System.IO.File.Create(strScriptPath);
BinaryWriter writer = new BinaryWriter(foutput, Encoding.UTF8);

string strLine;
foreach (FileInfo fi in lstFile)
{
   strLine = string.Empty;

   strLine = "\r\n\r\n/*--------- " + fi.Name + " -------------*/" + "\r\n\r\n";
   writer.Write(strLine);

   //some processing
}

foutput.Close();
MessageBox.Show("Done");

This code runs fine and create a script.sql file as required; but with random characters

      =

      /*--------- script1.sql -------------*/

      A

      /*--------- script2.sql -------------*/

      I

      /*--------- script3.sql -------------*/

      H

This is a consistent issue and I am not sure what is wrong.

  • 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-05T17:02:40+00:00Added an answer on June 5, 2026 at 5:02 pm

    Why are you using a BinaryWriter? As its name indicates this is for writing binary files, not text files. Use a StreamWriter instead. Also make sure you have wrapped IDisposable resources in using statements:

    strPath = txtInputFolder.Text;
    DirectoryInfo di = new DirectoryInfo(strPath);
    FileInfo[] lstFile = di.GetFiles("*.sql");
    
    string strScriptPath = System.IO.Path.Combine(strPath, lblOutput.Text);
    using (FileStream foutput = System.IO.File.Create(strScriptPath))
    using (StreamWriter writer = new StreamWriter(foutput, Encoding.UTF8))
    {
    
        string strLine;
        foreach (FileInfo fi in lstFile)
        {
            strLine = string.Empty;
    
            strLine = "\r\n\r\n/*--------- " + fi.Name + " -------------*/" + "\r\n\r\n";
            writer.Write(strLine);
            //some processing
        }
    }
    MessageBox.Show("Done");
    

    Or use LINQ to simplify your code:

    string strPath = txtInputFolder.Text;
    DirectoryInfo di = new DirectoryInfo(strPath);
    FileInfo[] lstFile = di.GetFiles("*.sql");
    
    string strScriptPath = Path.Combine(strPath, lblOutput.Text);
    
    File.WriteAllLines(
        strScriptPath, 
        lstFile.Select(
            fi => string.Format(
                "\r\n\r\n/*--------- {0} -------------*/\r\n\r\n{1}", 
                fi.Name, 
                File.ReadAllText(fi.FullName)
            )
        ),
        Encoding.UTF8
    );
    
    MessageBox.Show("Done");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working in Visual Studio 2008 and I would like for Edit > Outlining
I'm working on a visual studio 2008 add-in that will generate data-access code by
I'm working on a wpf project in visual studio 2008. I would like to
I am working in Visual studio 2008 and would like to be able to
While working with ASP.NET using Visual Studio (2008) I have discomfort issue: source code
Working in Visual Studio 2008. I'm trying to draw on a PNG image and
I'm working in Visual Studio 2008 using c#. Let's say I have 2 xsd
I'm working with visual studio 2008 developing software for windows CE 6.0, compact framework.
I'm trying to get edit-and-continue working with Visual Studio 2008 with an ASP.Net MVC
Working with C# Visual Studio 2008, MVC1. I'm creating an xml file by fetching

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.