private static void PutFile(string path, HttpListenerRequest request, HttpListenerResponse response) { FileStream fileStream = null; Stream dataStream = null; try { fileStream = new FileStream(path + "/" + request.Url.LocalPath, FileMode.Open, FileAccess.Read); byte[] buffer = new byte[4096]; int bytesRead = 0; int totalBytesRead = 0; dataStream = response.OutputStream; while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0) { totalBytesRead += bytesRead; dataStream.Write(buffer, 0, bytesRead); } float totalBlocks = totalBytesRead / 512; } catch (FormatException ex) {} catch (FileNotFoundException ex) {} catch (IOException ex) {} catch (Exception ex) {} finally { if (fileStream != null) { fileStream.Close(); } if (dataStream != null) { dataStream.Close(); } } }