I just ran up against a requirement to do a deep file and folder/directory copy in .NET (C# to be exact). A quick google didn't turn up any code, so I figured I'd post what I came up with. This is a somewhat naive implementation that may run out of steam for very deep folders or 1000s of files, but works great for most things. This implementation takes a source folder and a destination folder and copies the entire structure including files and folders from the source folder to the destination.

So without further ado:

private void CopyFolder(string folder, string destFolder)

foreach (string file in Directory.GetFiles(folder, "*.*", SearchOption.AllDirectories))
string fileName = Path.GetFileName(file);
string filePath = Path.GetDirectoryName(file.Substring(folder.Length + (folder.EndsWith("\\") ? 0 : 1)));
string destFilePath;

if (!string.IsNullOrEmpty(filePath))
string destFolderPath = Path.Combine(destFolder, filePath);


destFilePath = Path.Combine(destFolderPath, fileName);
destFilePath = Path.Combine(destFolder, fileName);

File.Copy(file, destFilePath);

I always try to develop my sites to be standards compliant, and this means using css for all formatting and positioning when possible. I keep having to look up how to center an image, so I decided to write a post so I always know where this information is.

To center an image, set the left and right margins to auto. This will make the margins fill the available space. You must also set the display to block so the image is treated as a content block. Here's a full css definition:

img {
display: block;
margin-left: auto;
margin-right: auto;