Category Archives: files

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

Make a metafile in C#

The example Display a Windows metafile (wmf) in C# explains how to display a metafile and why metafiles can produce better results than raster images such as those stored in bmp, jpg, or png formats. This example shows how a … Continue reading

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

Display a Windows metafile (wmf) in C#

A Windows metafile (wmf) is an image file that contains instructions for drawing shapes. In contrast, bitmap, PNG, JPG, and other raster image files indicate exactly what colors individual pixels should have. Because a Windows metafile contains drawing instructions instead … Continue reading

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

Play WAV files in C#

The System.Media.SoundPlayer class lets you easily play WAV files. This example uses the following PlayWav method to play WAV files. // The player making the current sound. private SoundPlayer Player = null; // Dispose of the current player and // … Continue reading

Posted in audio, files, multimedia | Tagged , , , , , , , , , , , , , | Leave a comment

Compress JPG files in a directory in C#

I wrote this example to help produce reduced-size versions of some of the thousands of pictures I’ve collected over the years. Unfortunately pictures you take with a modern camera or phone tend to be enormous. Fortunately most of my relatives … Continue reading

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