Tag Archives: files

Make a hangman game in C#

Special thanks to Jeff Scarterfield for the skeleton drawing used by the program. This example builds a simple hangman game that uses the dictionary created by the example Use LINQ to select words of certain lengths from a file in … Continue reading

Posted in algorithms, files, games, graphics, strings | Tagged , , , , , , , , , , , , | Leave a comment

Use LINQ to select words of certain lengths from a file in C#

This example uses LINQ to read a file, remove unwanted characters, select words of a specified length, and save the result in a new file. Recently I needed a big word list so I searched around for public domain dictionaries. … Continue reading

Posted in algorithms, files, LINQ | Tagged , , , , , , , , , , , | 2 Comments

Use a TextFieldParser to read fixed-width data in C#

This example uses a TextFieldParser object to load fixed-width data from a file that contains names and addresses. Each field has a fixed width. Some records also have ZIP+4 format ZIP codes (for example, 08109-2120) and the program should discard … Continue reading

Posted in classes, database, files, parsing | Tagged , , , , , , , , , , , , , , , | Leave a comment

Use a TextFieldParser to read delimited data in C#

This example uses a TextFieldParser object to parse a data file that contains name and address data. The data contains fields delimited by commas and semi-colons. Some records also have ZIP+4 format ZIP codes (for example, 08109-2120) and the program … Continue reading

Posted in classes, database, files, parsing | Tagged , , , , , , , , , , , , , | 2 Comments

Convert RTF and TXT files into DOCX files in C#

First add a reference to Microsoft.Office.Interop.Word. To make using the library easier, add this using statement: using Word = Microsoft.Office.Interop.Word; When you enter the input and output file names and click Convert, the program uses the following code to open … Continue reading

Posted in files, interoperability, Office, Word | Tagged , , , , , , , , , , , , , | Leave a comment

See what processes have a file locked in C#

In older versions of Windows, it was impossible to determine what processes had a file locked. The system kept track of the number of locks on a file and processes were responsible for incrementing and decrementing the count to represent … Continue reading

Posted in files, system | Tagged , , , , , , , , , | 1 Comment

See if a file is locked in C#

Some applications lock files so you cannot write, read, delete, or otherwise mess with them. For example, when you open a file in Microsoft Word, it locks the file so you cannot delete it or open it for writing with … Continue reading

Posted in files, system | Tagged , , , , , , , , , , , , , , | 3 Comments

Find files in the startup directory in C#

In some programs you may want to find files that were installed with the program. One way to do that is to put the files in the program’s installation directory. Open the Project menu, select Add Existing Item, find the … Continue reading

Posted in directories, files | Tagged , , , , , , , , , , , , | Leave a comment

List the locations of special folders in C#

The System.Environment class’s SpecialFolders enumeration lists special folders such as System, Cookies, Desktop, and so forth. The class’s GetFolderPath method returns the full path for one of the special folders values. This program uses the following code to enumerate the … Continue reading

Posted in directories, files, system | Tagged , , , , , , , , , , , | 2 Comments

Convert a metafile into a PNG file in C#

A metafile (WMF file) contains drawing commands that tell a program how to produce an image. This is very useful and allows you to resize the image without producing ugly anti-aliasing effects, but sometimes you may want a raster image … Continue reading

Posted in drawing, files, graphics, image processing | Tagged , , , , , , , , , , , , | Leave a comment