PageRenderTime 20ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/CHS Extranet/HAP.Web/WordVisualizer/CoreProperties.cs

#
C# | 128 lines | 71 code | 20 blank | 37 comment | 4 complexity | 99d5f82d365dad63289f9c37227929b3 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Office.DocumentFormat.OpenXml.Packaging;
  6. using System.Xml;
  7. namespace WordVisualizer.Core
  8. {
  9. /// <summary>
  10. /// WordprocessingML core properties
  11. /// </summary>
  12. [Serializable]
  13. public class CoreProperties
  14. {
  15. #region Constants
  16. public const string SchemaCoreProperties = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties";
  17. public const string SchemaDCProperties = "http://purl.org/dc/elements/1.1/";
  18. #endregion
  19. #region Properties
  20. /// <summary>
  21. /// Title
  22. /// </summary>
  23. public string Title { get; set; }
  24. /// <summary>
  25. /// Subject
  26. /// </summary>
  27. public string Subject { get; set; }
  28. /// <summary>
  29. /// Creator
  30. /// </summary>
  31. public string Creator { get; set; }
  32. /// <summary>
  33. /// Keywords
  34. /// </summary>
  35. public string Keywords { get; set; }
  36. /// <summary>
  37. /// Description
  38. /// </summary>
  39. public string Description { get; set; }
  40. /// <summary>
  41. /// LastModifiedBy
  42. /// </summary>
  43. public string LastModifiedBy { get; set; }
  44. /// <summary>
  45. /// Revision
  46. /// </summary>
  47. public string Revision { get; set; }
  48. /// <summary>
  49. /// Created
  50. /// </summary>
  51. public DateTime Created { get; set; }
  52. /// <summary>
  53. /// Modified
  54. /// </summary>
  55. public DateTime Modified { get; set; }
  56. #endregion
  57. #region Public static methods
  58. /// <summary>
  59. /// Create instance from OpenXML part
  60. /// </summary>
  61. /// <param name="part">OpenXML part</param>
  62. /// <returns>Instance</returns>
  63. public static CoreProperties FromCoreFileProperties(CoreFilePropertiesPart part)
  64. {
  65. // Temporary variable
  66. CoreProperties coreProperties = new CoreProperties();
  67. // Read XML
  68. using (XmlReader reader = new XmlTextReader(part.GetStream()))
  69. {
  70. while (reader.Read())
  71. {
  72. if (reader.NodeType == XmlNodeType.Element )
  73. {
  74. switch (reader.Name.ToLower())
  75. {
  76. case "dc:title":
  77. coreProperties.Title = reader.ReadElementContentAsString();
  78. break;
  79. case "dc:subject":
  80. coreProperties.Creator = reader.ReadElementContentAsString();
  81. break;
  82. case "dc:creator":
  83. coreProperties.Keywords = reader.ReadElementContentAsString();
  84. break;
  85. case "cp:keywords":
  86. coreProperties.Description = reader.ReadElementContentAsString();
  87. break;
  88. case "dc:description":
  89. coreProperties.LastModifiedBy = reader.ReadElementContentAsString();
  90. break;
  91. case "cp:lastmodifiedby":
  92. coreProperties.Revision = reader.ReadElementContentAsString();
  93. break;
  94. case "dcterms:created":
  95. coreProperties.Created = DateTime.Parse(reader.ReadElementContentAsString());
  96. break;
  97. case "dcterms:modified":
  98. coreProperties.Modified = DateTime.Parse(reader.ReadElementContentAsString());
  99. break;
  100. }
  101. }
  102. }
  103. }
  104. return coreProperties;
  105. }
  106. #endregion
  107. }
  108. }