Bladeren bron

Automatically create new core properties part rather than throw exception

master
GrabzIt 8 jaren geleden
bovenliggende
commit
4c5c2fc294
4 gewijzigde bestanden met toevoegingen van 38 en 4 verwijderingen
  1. 1
    1
      DocX/DocX.cs
  2. 23
    0
      DocX/HelperFunctions.cs
  3. 14
    3
      DocX/bin/Release/DocX.XML
  4. BIN
      DocX/bin/Release/DocX.dll

+ 1
- 1
DocX/DocX.cs Bestand weergeven

@@ -3871,7 +3871,7 @@ namespace Novacode
// If this document does not contain a coreFilePropertyPart create one.)
if (!package.PartExists(new Uri("/docProps/core.xml", UriKind.Relative)))
throw new Exception("Core properties part doesn't exist.");
HelperFunctions.CreateCorePropertiesPart(this);
XDocument corePropDoc;
PackagePart corePropPart = package.GetPart(new Uri("/docProps/core.xml", UriKind.Relative));

+ 23
- 0
DocX/HelperFunctions.cs Bestand weergeven

@@ -299,6 +299,29 @@ namespace Novacode
return settingsPart;
}
internal static void CreateCorePropertiesPart(DocX document)
{
PackagePart corePropertiesPart = document.package.CreatePart(new Uri("/docProps/core.xml", UriKind.Relative), "application/vnd.openxmlformats-package.core-properties+xml", CompressionOption.Maximum);
XDocument corePropDoc = XDocument.Parse(@"<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<cp:coreProperties xmlns:cp='http://schemas.openxmlformats.org/package/2006/metadata/core-properties' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:dcterms='http://purl.org/dc/terms/' xmlns:dcmitype='http://purl.org/dc/dcmitype/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<dc:title></dc:title>
<dc:subject></dc:subject>
<dc:creator></dc:creator>
<cp:keywords></cp:keywords>
<dc:description></dc:description>
<cp:lastModifiedBy></cp:lastModifiedBy>
<cp:revision>1</cp:revision>
<dcterms:created xsi:type='dcterms:W3CDTF'>"+ DateTime.UtcNow.ToString("s") + "Z" + @"</dcterms:created>
<dcterms:modified xsi:type='dcterms:W3CDTF'>" + DateTime.UtcNow.ToString("s") + "Z" + @"</dcterms:modified>
</cp:coreProperties>");
using (TextWriter tw = new StreamWriter(new PackagePartStream(corePropertiesPart.GetStream(FileMode.Create, FileAccess.Write))))
corePropDoc.Save(tw, SaveOptions.None);
document.package.CreateRelationship(corePropertiesPart.Uri, TargetMode.Internal, "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties");
}
internal static void CreateCustomPropertiesPart(DocX document)
{
PackagePart customPropertiesPart = document.package.CreatePart(new Uri("/docProps/custom.xml", UriKind.Relative), "application/vnd.openxmlformats-officedocument.custom-properties+xml", CompressionOption.Maximum);

+ 14
- 3
DocX/bin/Release/DocX.XML Bestand weergeven

@@ -3144,6 +3144,17 @@
<param name="name">The name of this Picture.</param>
<param name="descr">The description of this Picture.</param>
</member>
<member name="M:Novacode.Paragraph.ReplacePicture(Novacode.Picture,Novacode.Picture)">
<summary>
Replaces a Picture with a new one.
</summary>
<remarks>
Only the content of the picture will be replaced - positioning inside the document and all other attributes will be preserved.
</remarks>
<param name="toBeReplaced">The picture object to be replaced.</param>
<param name="replaceWith">The picture object that should be inserted instead of <paramref name="toBeReplaced"/>.</param>
<returns>The new <see cref="T:Novacode.Picture"/> object that replaces the old one.</returns>
</member>
<member name="M:Novacode.Paragraph.CreateEdit(Novacode.EditType,System.DateTime,System.Object)">
<summary>
Creates an Edit either a ins or a del with the specified content and date
@@ -4603,7 +4614,7 @@
</code>
</example>
<seealso cref="M:Novacode.DocX.AddImage(System.String,System.String)"/>
<seealso cref="!:AddImage(string, string)"/>
<seealso cref="M:Novacode.DocX.AddImage(System.IO.Stream,System.String)"/>
<seealso cref="P:Novacode.Paragraph.Pictures"/>
<seealso cref="M:Novacode.Paragraph.InsertPicture(Novacode.Picture,System.Int32)"/>
@@ -5135,7 +5146,7 @@
<param name="templateStream">The stream of the document template file.</param>
<param name="includeContent">Whether to copy the document template text content to document.</param>
</member>
<member name="M:Novacode.DocX.AddImage(System.String,System.String)">
<member name="M:Novacode.DocX.AddImage(System.String)">
<summary>
Add an Image into this document from a fully qualified or relative filename.
</summary>
@@ -5184,7 +5195,7 @@
}
</code>
</example>
<seealso cref="M:Novacode.DocX.AddImage(System.String,System.String)"/>
<seealso cref="!:AddImage(string, string)"/>
<seealso cref="M:Novacode.Paragraph.InsertPicture(Novacode.Picture,System.Int32)"/>
</member>
<member name="M:Novacode.DocX.AddHyperlink(System.String,System.Uri)">

BIN
DocX/bin/Release/DocX.dll Bestand weergeven


Laden…
Annuleren
Opslaan