Exemplo n.º 1
0
 private void cmdOK_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (Directory.Exists(PNPaths.Instance.TempDir))
         {
             Directory.Delete(PNPaths.Instance.TempDir, true);
         }
         Directory.CreateDirectory(PNPaths.Instance.TempDir);
         var zipPath = Path.Combine(PNPaths.Instance.TempDir, txtArchName.Text.Trim() + ".zip");
         using (var package = Package.Open(zipPath, FileMode.OpenOrCreate))
         {
             foreach (string f in _Files)
             {
                 var fileName = Path.GetFileName(f);
                 if (fileName == null)
                 {
                     continue;
                 }
                 var partUriFile     = PackUriHelper.CreatePartUri(new Uri(fileName, UriKind.Relative));
                 var packagePartFile = package.CreatePart(partUriFile, MediaTypeNames.Text.RichText, CompressionOption.Normal);
                 if (packagePartFile == null)
                 {
                     continue;
                 }
                 package.CreateRelationship(partUriFile, TargetMode.Internal, fileName);
                 using (var fileStream = new FileStream(f, FileMode.Open, FileAccess.Read))
                 {
                     PNStatic.CopyStream(fileStream, packagePartFile.GetStream());
                 }
             }
         }
         var archives = new List <string> {
             zipPath
         };
         PNNotesOperations.SendNotesAsAttachments(archives);
         DialogResult = true;
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }