Ejemplo n.º 1
0
        public PackagePart AddImagePart(Stream imageStream, string contentType)
        {
            var extension      = contentType.Substring(contentType.LastIndexOf("/", StringComparison.Ordinal) + 1);
            var imgPartUriPath = $"/word/media/{Guid.NewGuid()}.{extension}";
            var part           = package.CreatePart(new Uri(imgPartUriPath, UriKind.Relative), contentType, CompressionOption.Normal);

            using var partStream = new PackagePartStream(part.GetStream(FileMode.Create, FileAccess.Write));
            imageStream.CopyTo(partStream);
            return(part);
        }
Ejemplo n.º 2
0
 public static void SavePackagePart(PackagePart part, XDocument document)
 {
     using var stream            = new PackagePartStream(part.GetStream(FileMode.Create, FileAccess.Write));
     using TextWriter textWriter = new StreamWriter(stream);
     document.Save(textWriter, SaveOptions.None);
 }