Skip to content


Visual Studio 2008 text file encoding problems

‘…’ is not recognized as an internal or external command…

Encode error in batch file

Encode error in batch file

Is an error I got in Visual Studio 2008, when simply making a new .bat file to install a feature (code module for SharePoint) using script. The text cant be input here in WordPress so I have attached a picture above from my output window.

I often add a postbuild event for my SharePoint projects to easier install my features etc. to speed up development. I use the following:

CD $(ProjectDir)
Install.bat

I have done this a lot of time, but not in VS 2008

I had problems finding out what on earth was going on. It seemed like no matter what I wrote in the batch file it would simply not work.

I found out by scouring the Net, that the problem was encoding of the file. The standard encoding format for new text files in VS 2008 is UTF-8 and that is not the correct encoding for a batchfile. It needs to be saved in ASCII (ANSI in Notepad) format.

I will explain how to change the encoding in Visual Studio and Notepad.

Visual Studio 2008:

1: Open the “File” menu and choose “Save … As”

Save ... As

Save ... As

2: Click the little down arrow and choose “Save with Encoding”

Save with encoding

Save with encoding

This is what it looks like when you create a standard text file in VS2008:

Wrong encoding (UTF-8)

Wrong encoding (UTF-8)

3: Choose US-ASCII to save in correct encoding

Choose ASCII encoding

Choose ASCII encoding

My output on this simple feature is now:

Batch file runs correctly now

Batch file runs correctly now

You can also just change the encoding in Notepad which is a bit easier:

1: Simply open the file with Notepad and choose “Save As” and choose ANSI from the dropdownlist

Change encoding using Notepad

Change encoding using Notepad

Hope this helps someone.

Recommended reading

These book will help you tremendiously as a developer using Visual Studio 2008, if you are a .NET or a SharePoint programmer or not. Stop doing everything the hard way, and learn the ins and out of Visual Studio 2008.

DeliciousDiggTwitterFacebookLinkedInStumbleUponNewsVineTechnorati FavoritesSlashdotShare

Related posts:

  1. Fast generation of Guid in Visual Studio (2005 and 2008)
  2. Enable intellisense in Visual Studio for SharePoint / WSS xml files

Posted in Visual Studio.


3 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Andrew says

    Solid. This was driving me crazy in VS2008. Copying existing .bat files just wasn’t going to cut it. Thanks for the post!

  2. Luciano says

    Man, it saved my life!!! I was having problems with SQLCMD in a .bat using scripts divided in .sql files. Then I changed the .sql files encoding.

    Thanks!!!

Continuing the Discussion



Some HTML is OK

or, reply to this post via trackback.



Page optimized by WP Minify WordPress Plugin