locked
Add files to compressed folder with shell RRS feed

  • Question

  • Hello,

    In my application, i can browse compressed folders with shell ( with FolderItem, etc...)

    Like in explorer, I want to be able to paste some files into Zip. For that, I use the ifileoperation which replace shfileoperation) but I have an error "d:\temp.zip is not available".

    (note : i can delete file into the compressed folder with the ifileoperation)

    Thank you for your help


    Tuesday, September 10, 2013 8:30 PM

Answers

  • Hi,

    I was using below Shell method and it seems working fine, it will good if you can provide some sample so I can test the same.

        Dim sc As New Shell32.Shell()
    
        Sub Main()
            Zip()
            Console.WriteLine("Check zip file and press enter")
            Console.ReadLine()
            AppendToZip()
            Console.WriteLine("Check zip file and press enter")
            Console.ReadLine()
        End Sub
    
        Sub Zip()        
            Dim startBuffer() As Byte = {80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
            FileIO.FileSystem.WriteAllBytes("E:\empty.zip", startBuffer, False)
            Dim input As Shell32.Folder = sc.NameSpace("E:\filesToZip")        
            Dim output As Shell32.Folder = sc.NameSpace("E:\empty.zip")
            output.CopyHere(input.Items)
        End Sub
    
        Sub AppendToZip()
            Dim input As Shell32.Folder = sc.NameSpace("E:\filesToZip1")
            Dim output As Shell32.Folder = sc.NameSpace("E:\empty.zip")
            output.CopyHere(input.Items)
        End Sub


    Regards
    Nayan Paregi (MCTS)
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    • Proposed as answer by PaulDAndrea Monday, September 16, 2013 9:55 PM
    • Marked as answer by Eason_H Tuesday, September 17, 2013 1:25 AM
    Wednesday, September 11, 2013 2:48 AM
  • This is a C# forum Nayan... Here it is converted to C#

    Shell32.Shell sc = new Shell32.Shell();
    public void Main()
    {
    	Zip();
    	Console.WriteLine("Check zip file and press enter");
    	Console.ReadLine();
    	AppendToZip();
    	Console.WriteLine("Check zip file and press enter");
    	Console.ReadLine();
    }
    public void Zip()
    {
    	byte[] startBuffer = {
    		80,
    		75,
    		5,
    		6,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0
    	};
    	Microsoft.VisualBasic.FileIO.FileSystem.WriteAllBytes("E:\\empty.zip", startBuffer, false);
    	Shell32.Folder input = sc.NameSpace("E:\\filesToZip");
    	Shell32.Folder output = sc.NameSpace("E:\\empty.zip");
    	output.CopyHere(input.Items);
    }
    public void AppendToZip()
    {
    	Shell32.Folder input = sc.NameSpace("E:\\filesToZip1");
    	Shell32.Folder output = sc.NameSpace("E:\\empty.zip");
    	output.CopyHere(input.Items);
    }

    Using http://www.developerfusion.com/tools/convert/vb-to-csharp/


    You can also use http://codeconverter.sharpdevelop.net/SnippetConverter.aspx

    • Edited by PaulDAndrea Wednesday, September 11, 2013 4:04 AM typo
    • Proposed as answer by PaulDAndrea Monday, September 16, 2013 9:55 PM
    • Marked as answer by Eason_H Tuesday, September 17, 2013 1:24 AM
    Wednesday, September 11, 2013 3:55 AM

All replies

  • Hi,

    I was using below Shell method and it seems working fine, it will good if you can provide some sample so I can test the same.

        Dim sc As New Shell32.Shell()
    
        Sub Main()
            Zip()
            Console.WriteLine("Check zip file and press enter")
            Console.ReadLine()
            AppendToZip()
            Console.WriteLine("Check zip file and press enter")
            Console.ReadLine()
        End Sub
    
        Sub Zip()        
            Dim startBuffer() As Byte = {80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
            FileIO.FileSystem.WriteAllBytes("E:\empty.zip", startBuffer, False)
            Dim input As Shell32.Folder = sc.NameSpace("E:\filesToZip")        
            Dim output As Shell32.Folder = sc.NameSpace("E:\empty.zip")
            output.CopyHere(input.Items)
        End Sub
    
        Sub AppendToZip()
            Dim input As Shell32.Folder = sc.NameSpace("E:\filesToZip1")
            Dim output As Shell32.Folder = sc.NameSpace("E:\empty.zip")
            output.CopyHere(input.Items)
        End Sub


    Regards
    Nayan Paregi (MCTS)
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    • Proposed as answer by PaulDAndrea Monday, September 16, 2013 9:55 PM
    • Marked as answer by Eason_H Tuesday, September 17, 2013 1:25 AM
    Wednesday, September 11, 2013 2:48 AM
  • This is a C# forum Nayan... Here it is converted to C#

    Shell32.Shell sc = new Shell32.Shell();
    public void Main()
    {
    	Zip();
    	Console.WriteLine("Check zip file and press enter");
    	Console.ReadLine();
    	AppendToZip();
    	Console.WriteLine("Check zip file and press enter");
    	Console.ReadLine();
    }
    public void Zip()
    {
    	byte[] startBuffer = {
    		80,
    		75,
    		5,
    		6,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0,
    		0
    	};
    	Microsoft.VisualBasic.FileIO.FileSystem.WriteAllBytes("E:\\empty.zip", startBuffer, false);
    	Shell32.Folder input = sc.NameSpace("E:\\filesToZip");
    	Shell32.Folder output = sc.NameSpace("E:\\empty.zip");
    	output.CopyHere(input.Items);
    }
    public void AppendToZip()
    {
    	Shell32.Folder input = sc.NameSpace("E:\\filesToZip1");
    	Shell32.Folder output = sc.NameSpace("E:\\empty.zip");
    	output.CopyHere(input.Items);
    }

    Using http://www.developerfusion.com/tools/convert/vb-to-csharp/


    You can also use http://codeconverter.sharpdevelop.net/SnippetConverter.aspx

    • Edited by PaulDAndrea Wednesday, September 11, 2013 4:04 AM typo
    • Proposed as answer by PaulDAndrea Monday, September 16, 2013 9:55 PM
    • Marked as answer by Eason_H Tuesday, September 17, 2013 1:24 AM
    Wednesday, September 11, 2013 3:55 AM