public static bool IsAnyTextType(this Part part) { var contentType = part?.ContentType; return(ContentTypes.IsXmlType(contentType) || ContentTypes.IsCodeType(contentType) || ContentTypes.IsTextType(contentType)); }
/// <summary> /// Get the effective extension for a part /// </summary> private string GetPartExtension(Part part) { if (ContentTypes.IsXmlType(part.ContentType)) { return(".xml"); } else { return(part.GetFileInfo().Extension); } }
private void SetResponseToPart(HttpListenerContext context, Uri url, Part part) { if (part != null) { using (var partStream = part.GetFileInfo().OpenRead()) { context.Response.ContentType = part.ContentType; if (Settings.EditorFormatXmlOnLoad && ContentTypes.IsXmlType(part.ContentType)) { var writerSettings = new XmlWriterSettings() { Indent = true, }; using (var textReader = new StreamReader(partStream)) using (var xmlWriter = XmlWriter.Create(context.Response.OutputStream, writerSettings)) { var elt = XElement.Parse(textReader.ReadToEnd()); elt.Save(xmlWriter); } } else if ((part.ContentType == "image/x-emf") || (part.ContentType == "image/x-wmf")) { context.Response.ContentType = "image/png"; MetafileConverter.CopyToImage(partStream, context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png); } else { context.Response.ContentType = part.ContentType; partStream.CopyTo(context.Response.OutputStream); } } } context.Response.StatusCode = 200; context.Response.OutputStream.Close(); }
public BitmapCollection <BitmapSource> GetIconForContentType(string contentType) { if (string.Equals(contentType, "application/vnd.openxmlformats-package.relationships+xml", StringComparison.Ordinal)) { return(RelsIcon); } if (ContentTypes.IsSupportedAudioType(contentType)) { return(AudioIcon); } if (ContentTypes.IsSupportedImageType(contentType)) { return(ImageIcon); } if (ContentTypes.IsSupportedVideoType(contentType)) { return(VideoIcon); } if (ContentTypes.IsXmlType(contentType)) { return(XmlIcon); } if (ContentTypes.IsXmlType(contentType)) { return(CodeIcon); } switch (contentType) { case "application/rtf": case "message/rfc822": return(DocumentIcon); case "application/vnd.openxmlformats-officedocument.vmlDrawing": return(CodeIcon); case "application/msword": case "application/vnd.ms-word.document.macroEnabled.12": case "application/vnd.openxmlformats-officedocument.wordprocessingml.document": return(WordIcon); case "application/vnd.ms-powerpoint": case "application/vnd.ms-powerpoint.presentation.macroEnabled.12": case "application/vnd.openxmlformats-officedocument.presentationml.presentation": case "application/vnd.openxmlformats-package.relationships+xml": case "application/vnd.ms-powerpoint.slide.macroEnabled.12": case "application/vnd.openxmlformats-officedocument.presentationml.slide": return(PptIcon); case "application/vnd.visio": case "application/vnd.ms-visio.drawing.macroEnabled": case "application/vnd.ms-visio.drawing": return(VisioIcon); case "application/vnd.ms-excel": case "application/vnd.ms-excel.sheet.binary.macroEnabled.12": case "application/vnd.ms-excel.sheet.macroEnabled.12": case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": return(ExcelIcon); default: return(UnknownIcon); } }