public bool isDicom(string filename) { FileStream fs = File.OpenRead(filename); byte[] data = new byte[132]; fs.Read(data, 0, data.Length); int b0 = data[0] & 255, b1 = data[1] & 255, b2 = data[2] & 255, b3 = data[3] & 255; if (data[128] == 68 && data[129] == 73 && data[130] == 67 && data[131] == 77) { return true; } else if ((b0 == 8 || b0 == 2) && b1 == 0 && b3 == 0) { return true; } return false; }