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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:24:07+00:00 2026-05-16T04:24:07+00:00

I am using the MSBuild copy and then Concat to concatenate multiple SQL files.

  • 0

I am using the MSBuild copy and then Concat to concatenate multiple SQL files. Some of the SQL files are in some other format (opens in notepad), but after Concat gets to the files, there are strange characters all over the resulting files.

Can anyone help me, has anyone experienced this before? How can I convert all SQL files to ascii, or make the Concat task work properly?

  • 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-05-16T04:24:08+00:00Added an answer on May 16, 2026 at 4:24 am

    Well I got around it by writing a utility C# class. It is not designed to handle exceptions, they are handled by the calling class or unhandled in the console.

    It converts the files to ASCII, removes any invalid characters and rewrites the files.

    I spent a while wondering why I was getting access-denied issues, make sure you have all the files you want to convert checked out before you convert them!

    Here it is if you are interested:

    using System;
    using System.IO;
    using System.Text;
    
    /// <summary>
    /// Manages encoding of text files.
    /// </summary>
    public class TextFileEncoding
    {
        /// <summary>
        /// Main command-line entry.
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                string argParam = args[0].ToString().Trim().ToLower();
                switch (argParam)
                {
                    // Return encoding for a file.
                    case "get":
                        Encoding enc = GetEncoding(args[1].ToString());
                        Console.WriteLine(enc.EncodingName);
                        break;
    
                    // convert encoding for a path with a given pattern to ASCII.
                    case "toascii":
                        int count = ConvertToAscii(args[1].ToString(), args.Length == 3 ? args[2] : "*.*");
                        Console.WriteLine("Successfully converted " + count + " files.");
                        break;
                    default:
                        Console.WriteLine("Invalid parameter. Expected get or toascii");
                        break;
                }
            }
            else
            {
                Console.WriteLine("Missing filename parameter.\nFormat: TextFileEncoding.exe [get|toascii] <TextFile> <Path> <Pattern>");
            }
        }
    
        /// <summary>
        /// Returns the encoding of the filename at the specified path.
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public static Encoding GetEncoding(string filename)
        {
            StreamReader fileStream = new StreamReader(filename, true);
            return GetEncoding(fileStream);
        }
    
        /// <summary>
        /// Returns the encoding of the file stream.
        /// </summary>
        /// <param name="fileStream"></param>
        /// <returns></returns>
        public static Encoding GetEncoding(StreamReader fileStream)
        {
            return fileStream.CurrentEncoding;
        }
    
        /// <summary>
        /// Converts all files to ascii encoding.
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static int ConvertToAscii(string path, string pattern)
        {
            DirectoryInfo pathInfo = new DirectoryInfo(path);
            int count = 0;
    
            // Get files in directory, recursively.
            FileInfo[] files = pathInfo.GetFiles(pattern, SearchOption.AllDirectories);
    
            foreach (FileInfo file in files)
            {
                // Encode to ASCII.
                if (EncodeAscii(file))
                {
                    count++;
                }
            }
    
            return count;
        }
    
        /// <summary>
        /// Converts file to ascii.
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        private static bool EncodeAscii(FileInfo file)
        {
            ASCIIEncoding encoder = new ASCIIEncoding();
    
            // Get content of file as string.
            string content = File.ReadAllText(file.FullName);
    
            // Convert to an ASCII byte array.
            byte[] asciiString = encoder.GetBytes(content);
    
            // Convert to string, so all unknown characters get removed.
            string cleanString = encoder.GetString(asciiString);
    
            // Convert back to byte array for writing to file.
            byte[] cleanBytes = encoder.GetBytes(cleanString);
    
            // Delete and rewrite file as ASCII.
            file.Delete();
            File.WriteAllBytes(file.FullName, cleanBytes);
    
            return true;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using MsBuild and the TransformXml task to set up some web.config files. That's
I'm trying to copy a folder recursively to multiple destination folders using MSBuild's Copy
Hy there! I'm using this piece of code, to copy some files on post-build-event:
Currently I do the following: Create package using msbuild something.csproj /P:Configuration:Some /T:Package After that
I'm using MSBUILD macros in my .csproj files for AfterBuild events mainly just to
I (successfully) deployed some sharepoint2010 - Webparts using msbuild. Everything works fine until I
I'm looking to compile my Delphi 2010 project using MSBuild, but something isn't right,
We are trying to deploy a web service via MSbuild and then using MSDeploy
I am using MSBuild extensionpack. I'd like to copy the entire contents of the
I have a msbuild script that builds multiple projects using TeamCity. It builds a

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.