By using the Automation “‘Microsoft Shell Controls And Automation’.Shell” you can unzip a file within Dynamics NAV.

Create a Global

Name DataType Subtype
SystemShellControl Automation ‘Microsoft Shell Controls And Automation’.Shell
SystemShellItem Automation ‘Microsoft Shell Controls And Automation’.FolderItem
SystemShellItems Automation ‘Microsoft Shell Controls And Automation’.FolderItems
FileName Text
ZipFileName Text
DestFolderName Text
Index Integer
Pos Integer

And then simply
[code]ZipFileName := ‘C:\TEMP\ZipFile.Zip’;
DestFolderName := ‘C:\TEMP\’;
SystemShellItems := SystemShellControl.NameSpace(ZipFileName).Items;
SystemShellControl.NameSpace(DestFolderName).CopyHere(SystemShellItems);
FOR Index := 1 TO SystemShellItems.Count DO BEGIN
SystemShellItem := SystemShellItems.Item(Index – 1);
IF ISSERVICETIER THEN
FileName := SystemShellItem.Path
ELSE
FOR Pos := 1 TO STRLEN(SystemShellItem.Path) DO
IF COPYSTR(SystemShellItem.Path,Pos,1) = ‘\’ THEN
FileName := COPYSTR(SystemShellItem.Path,Pos + 1);
// Do what ever you whant to DestFolderName + FileName
END;[/code]

5 thoughts on “Unzip Files

  1. Igelown says:

    Hey Gunnar,

    I built this example in a Codeunit. But this Examplet does not work, when I viewed it from a web service…

    can you help me?

    Thank you

  2. If you send me your code I might be able to do that.

    1. Igelown says:

      Thank you for help… Both Parts doesnt work in RTC or from Webservice

      VAR :

      Shell32 Automation ‘Microsoft Shell Controls And Automation’.Shell
      SrcFolder Automation ‘Microsoft Shell Controls And Automation’.Folder
      DstFolder Automation ‘Microsoft Shell Controls And Automation’.Folder
      SrcItems Automation ‘Microsoft Shell Controls And Automation’.FolderItems3
      FileSystemObject Automation ‘Windows Script Host Object Model’.FileSystemObject
      OCAMWebserviceTest Record OC AM WebserviceTest
      SystemShellControl Automation ‘Microsoft Shell Controls And Automation’.Shell
      SystemShellItem Automation ‘Microsoft Shell Controls And Automation’.FolderItem
      SystemShellItems Automation ‘Microsoft Shell Controls And Automation’.FolderItems
      Index Integer
      Pos Integer
      FileName Text 1024

      CODE:

      IF ISCLEAR(FileSystemObject) THEN
      CREATE(FileSystemObject);

      IF ZipFileName = ” THEN
      EXIT;
      IF NOT FileSystemObject.FolderExists(DestFolderName) THEN
      FileSystemObject.CreateFolder(DestFolderName);

      IF ISCLEAR(Shell32) THEN
      CREATE(Shell32);

      IF FileSystemObject.FileExists(ZipFileName) THEN BEGIN

      SrcFolder := Shell32.NameSpace(ZipFileName);
      DstFolder := Shell32.NameSpace(DestFolderName);
      SrcItems := SrcFolder.Items;
      DstFolder.CopyHere(SrcItems);

      END;
      CLEAR(Shell32);
      CLEAR(DstFolder);
      CLEAR(SrcItems);

      {IF ISCLEAR(SystemShellControl) THEN
      CREATE(SystemShellControl);

      SystemShellItems := SystemShellControl.NameSpace(ZipFileName).Items;
      SystemShellControl.NameSpace(DestFolderName).CopyHere(SystemShellItems);
      FOR Index := 1 TO SystemShellItems.Count DO BEGIN
      SystemShellItem := SystemShellItems.Item(Index – 1);
      IF ISSERVICETIER THEN
      FileName := SystemShellItem.Path
      ELSE
      FOR Pos := 1 TO STRLEN(SystemShellItem.Path) DO
      IF COPYSTR(SystemShellItem.Path,Pos,1) = ‘\’ THEN
      FileName := COPYSTR(SystemShellItem.Path,Pos + 1);
      // Do what ever you whant to DestFolderName + FileName
      END;}

  3. Here is a code that works for me both in Classic and in RTC client.

    IF URL = ” THEN EXIT;

    IF NOT CONFIRM(Text016,TRUE,URL) THEN EXIT;

    IF GUIALLOWED THEN BEGIN
    Window.OPEN(‘#1#############################################\\’ + Text017 + ‘\’ + Text018);
    Window.UPDATE(1,STRSUBSTNO(Text012,URL));
    END;

    IF ISSERVICETIER THEN BEGIN
    HTTPRequest := HTTPRequest.XMLHTTPRequestClass;
    HTTPRequest.open(‘GET’,URL,FALSE,”,”);
    HTTPRequest.send(”);
    IF HTTPRequest.status <> 200 THEN
    ERROR(Text023,HTTPRequest.status,HTTPRequest.statusText);

    END ELSE BEGIN
    CREATE(WinHTTP,TRUE,TRUE);

    WinHTTP.open(‘GET’,URL,FALSE);
    WinHTTP.send(”);

    IF WinHTTP.status <> 200 THEN
    ERROR(Text023,WinHTTP.status,WinHTTP.statusText);
    END;

    IF ISCLEAR(SystemShellFilesSystem) THEN
    CREATE(SystemShellFilesSystem,TRUE,TRUE);
    IF ISCLEAR(SystemShellControl) THEN
    CREATE(SystemShellControl,TRUE,TRUE);

    TempFolderName := GetTempPath;
    TempFileName := TempFolderName + ‘\NAV_NR.ZIP’;
    TempFolderName := TempFolderName + ‘\NAV_NR’;
    IF SystemShellFilesSystem.FolderExists(TempFolderName) THEN BEGIN
    SystemShellFilesSystem.DeleteFolder(TempFolderName,TRUE);
    SLEEP(100);
    END;

    SystemShellFilesSystem.CreateFolder(TempFolderName);
    IF SystemShellFilesSystem.FileExists(TempFileName) THEN
    SystemShellFilesSystem.DeleteFile(TempFileName);

    IF ISSERVICETIER THEN BEGIN
    ClientFile.WriteAllBytes(TempFileName,HTTPRequest.responseBody);
    END ELSE BEGIN
    TempFile.CREATE(TempFileName);
    TempFile.CREATEOUTSTREAM(OutStr);
    InStr := WinHTTP.responseStream;
    COPYSTREAM(OutStr,InStr);
    TempFile.CLOSE;
    END;

    SystemShellItems := SystemShellControl.NameSpace(TempFileName).Items;
    SystemShellControl.NameSpace(TempFolderName).CopyHere(SystemShellItems);
    FOR Index := 1 TO SystemShellItems.Count DO BEGIN
    SystemShellItem := SystemShellItems.Item(Index – 1);
    FileName := RemovePath(SystemShellItem.Path);
    IF ISSERVICETIER THEN BEGIN
    TempText.ADDTEXT(ClientFile.ReadAllText(TempFolderName + ‘\’ + FileName));
    TempBlob.Blob.CREATEOUTSTREAM(OutStr);
    TempText.WRITE(OutStr);
    TempBlob.Blob.CREATEINSTREAM(InStr);
    END ELSE BEGIN
    TempFile.OPEN(TempFolderName + ‘\’ + FileName);
    TempFile.CREATEINSTREAM(InStr);
    END;
    IF GUIALLOWED THEN
    Window.UPDATE(1,STRSUBSTNO(Text019,FileName));
    ReadTextStream(InStr,ConvertCP);
    IF NOT ISSERVICETIER THEN
    TempFile.CLOSE;
    SystemShellFilesSystem.DeleteFile(TempFolderName + ‘\’ + FileName);
    END;

    IF SystemShellFilesSystem.FileExists(TempFileName) THEN
    SystemShellFilesSystem.DeleteFile(TempFileName);
    IF SystemShellFilesSystem.FolderExists(TempFolderName) THEN
    SystemShellFilesSystem.DeleteFolder(TempFolderName,TRUE);

    CLEAR(WinHTTP);
    CLEAR(SystemShellFilesSystem);
    CLEAR(SystemShellControl);
    IF GUIALLOWED THEN
    Window.CLOSE;

  4. kim says:

    Hi,

    Check if this will help you..
    http://www.mibuso.com/dlinfo.asp?FileID=1445

    kim estacio

Leave a Reply

%d bloggers like this: