In order to test the latency on a specific server configuration, we simply wanted to test the throughput rate of downloading large files. The only question is: how can you efficiently create several (large) files with an exact size?
As easy as two lines, I can tell you. The snippet below basically writes a file with spaces, using a stream, until the designated size is reached. This to accomplish an exact file size.
/// <summary>
/// Creates a file with a specific size.
/// </summary>
/// <param name="outputFilePath">The full output path for the file. Overwrites if exists.</param>
/// <param name="length">Filesize in bytes</param>
static void CreateFileWithSpecificSize(string outputFilePath, long length)
{
using (var stream = new FileStream(outputFilePath, FileMode.Create, FileAccess.Write, FileShare.None))
{
stream.SetLength(length);
}
}