/// <summary> /// Dumps the contents of the specified file in the HTTP response. /// Returns an error if there is a problem in opening/closing the file. /// </summary> /// <param name="path">The path.</param> /// <param name="context">Http context to respond to.</param> private static void DumpFile(string path, HttpListenerContext context) { try { string mimeType = MimeTypeDetection.GetMimeFromFile(path); context.Response.ContentType = mimeType; //// context.Response.SendChunked = true; using (FileStream handle = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { handle.CopyTo(context.Response.OutputStream); } } finally { context.Response.Close(); } }
/// <summary> /// Detects the type of the content in a file. /// </summary> /// <param name="path">The path to the file.</param> /// <returns>A MIME type.</returns> private static string DetectContentType(string path) { return(MimeTypeDetection.GetMimeFromFile(path)); }