Skip to main content
Announcements
Defect acknowledgement with Nprinting Engine May 2022 SR2, please READ HERE
cancel
Showing results for 
Search instead for 
Did you mean: 
Cascader
Creator
Creator

HTML reports generated as .zip files in Npriting 21

Hi all, 

I searched for work around, how to extract html reports from .zip file, however I couldn't find effective solution yet!

I have created a batch script that exctract the html file from .zip file and then rename it as same as .zip file name and lastly delete the .zip file

@Echo off
for /F %%I IN ('dir /b *.zip') DO (
del "%%~nI.html"
"C:\Program Files\7-Zip\7z.exe" x -o"%%~dpI" "%%I" -aoa
for /F "delims=" %%f in ('dir /b *.Html') do (
ren "%%f" "%%~nI.html"

::del "%%~nI.zip"
)
)

however this script is some cases fails.

if another one has a work around that fix this issue please share with me.

 

Thanks

Labels (3)
2 Solutions

Accepted Solutions
Ruggero_Piccoli
Support
Support

Hi,

There are some examples online to solve the issue of uncompressing all zipped files of a folder. For example googling I found https://stackoverflow.com/questions/17077964/windows-batch-script-to-unzip-files-in-a-directory (I have not tested it).

You can deliver all Qlik NPrinting HTML reports to a single folder and test one of the batch scripts you can freely find online. In case of issues with the batch script you can generate the reports again by manually running the publish task.

At the moment (latest release is May 2021 SR4) there is not an option to export HTML unzipped from Qlik NPrinting. HTML reports are always delivered zipped https://help.qlik.com/en-US/nprinting/February2021/Content/NPrinting/DistributionSchedulesAutomation...

Best Regards,

Ruggero



Best Regards,
Ruggero
---------------------------------------------
When applicable please mark the appropriate replies as CORRECT. This will help community members and Qlik Employees know which discussions have already been addressed and have a possible known solution. Please mark threads with a LIKE if the provided solution is helpful to the problem, but does not necessarily solve the indicated problem. You can mark multiple threads with LIKEs if you feel additional info is useful to others.

View solution in original post

Cascader
Creator
Creator
Author

I have created a C# console program that do the job in very efficient way, even has a better performance from my above batch script. 

i'm sharing it here in case anyone face this problem, can use this code:

*** envControl is text file path that contains the directories you want to perform extracting html from .zip operation. write every directory path in a separate line.

string envControl = @"C:\text.txt"

public void Unzip()
{
using (StreamReader sr = File.OpenText(envControl))
{
string s = String.Empty;
while ((s = sr.ReadLine()) != null)
{
string extractPath = s;


//+++++++++++++++++++++++++++++++++++++++++
string fileNameToDetele = "";
string[] files =
Directory.GetFiles(extractPath, "*.zip", SearchOption.TopDirectoryOnly);
foreach (var item in files)
{
fileNameToDetele = Path.GetFileNameWithoutExtension(item) + ".html";
if (File.Exists(extractPath + fileNameToDetele))
{
File.Delete(extractPath + fileNameToDetele);
}
RenameZipEntries(item);
System.IO.Compression.ZipFile.ExtractToDirectory(item, extractPath);
if (File.Exists(item))
{
File.Delete(item);
}

}
//+++++++++++++++++++++++++++++++++++++++++
}
}
}

private static void RenameZipEntries(string file)
{
using (var archive = new ZipArchive(File.Open(file, FileMode.Open, FileAccess.ReadWrite), ZipArchiveMode.Update))
{
var entries = archive.Entries.ToArray();
foreach (var entry in entries)
{
var newEntry = archive.CreateEntry(Path.GetFileNameWithoutExtension(file) + ".html");
using (var a = entry.Open())
using (var b = newEntry.Open())
a.CopyTo(b);
entry.Delete();
}
}
}

View solution in original post

2 Replies
Ruggero_Piccoli
Support
Support

Hi,

There are some examples online to solve the issue of uncompressing all zipped files of a folder. For example googling I found https://stackoverflow.com/questions/17077964/windows-batch-script-to-unzip-files-in-a-directory (I have not tested it).

You can deliver all Qlik NPrinting HTML reports to a single folder and test one of the batch scripts you can freely find online. In case of issues with the batch script you can generate the reports again by manually running the publish task.

At the moment (latest release is May 2021 SR4) there is not an option to export HTML unzipped from Qlik NPrinting. HTML reports are always delivered zipped https://help.qlik.com/en-US/nprinting/February2021/Content/NPrinting/DistributionSchedulesAutomation...

Best Regards,

Ruggero



Best Regards,
Ruggero
---------------------------------------------
When applicable please mark the appropriate replies as CORRECT. This will help community members and Qlik Employees know which discussions have already been addressed and have a possible known solution. Please mark threads with a LIKE if the provided solution is helpful to the problem, but does not necessarily solve the indicated problem. You can mark multiple threads with LIKEs if you feel additional info is useful to others.
Cascader
Creator
Creator
Author

I have created a C# console program that do the job in very efficient way, even has a better performance from my above batch script. 

i'm sharing it here in case anyone face this problem, can use this code:

*** envControl is text file path that contains the directories you want to perform extracting html from .zip operation. write every directory path in a separate line.

string envControl = @"C:\text.txt"

public void Unzip()
{
using (StreamReader sr = File.OpenText(envControl))
{
string s = String.Empty;
while ((s = sr.ReadLine()) != null)
{
string extractPath = s;


//+++++++++++++++++++++++++++++++++++++++++
string fileNameToDetele = "";
string[] files =
Directory.GetFiles(extractPath, "*.zip", SearchOption.TopDirectoryOnly);
foreach (var item in files)
{
fileNameToDetele = Path.GetFileNameWithoutExtension(item) + ".html";
if (File.Exists(extractPath + fileNameToDetele))
{
File.Delete(extractPath + fileNameToDetele);
}
RenameZipEntries(item);
System.IO.Compression.ZipFile.ExtractToDirectory(item, extractPath);
if (File.Exists(item))
{
File.Delete(item);
}

}
//+++++++++++++++++++++++++++++++++++++++++
}
}
}

private static void RenameZipEntries(string file)
{
using (var archive = new ZipArchive(File.Open(file, FileMode.Open, FileAccess.ReadWrite), ZipArchiveMode.Update))
{
var entries = archive.Entries.ToArray();
foreach (var entry in entries)
{
var newEntry = archive.CreateEntry(Path.GetFileNameWithoutExtension(file) + ".html");
using (var a = entry.Open())
using (var b = newEntry.Open())
a.CopyTo(b);
entry.Delete();
}
}
}