locked
How to create zip file of a folder in c# windows application RRS feed

  • Question

  • hi there, i have a folder in my project and i want to create zip file of that folder. i write the code but it doesnt  work. please guide how to solve it.

    private void button4_Click(object sender, EventArgs e)
            {
                try
                {
                    if (string.IsNullOrEmpty(textBox2.Text))
                    {
                        MessageBox.Show("Please Select Saving Location", "Location Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    string folderpath = Path.GetDirectoryName(Application.ExecutablePath) + "\\Pictures\\";
                    string zippingpath = textBox2.Text;
                    ZipFile.CreateFromDirectory(folderpath, zippingpath);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

    guide me please..

    Tuesday, January 22, 2019 4:08 PM

Answers

  • Hi John6272

    Thank you for posting here.

    For your question, I make a simple code(the same as you)to test it, it works well.

    I suggest you could check if the folderpath or zippingpath is in the right path by setting a breakpoint.

    If it still does not work, I want to confirm if it throws any exception, if so, please share the information about the exception, if not, could you provide more details to reproduce your problem?

    Hope my advice could be helpful.

    Best regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by John6272 Sunday, February 10, 2019 4:08 PM
    Wednesday, January 23, 2019 1:35 AM

All replies

  • Hi John6272

    Thank you for posting here.

    For your question, I make a simple code(the same as you)to test it, it works well.

    I suggest you could check if the folderpath or zippingpath is in the right path by setting a breakpoint.

    If it still does not work, I want to confirm if it throws any exception, if so, please share the information about the exception, if not, could you provide more details to reproduce your problem?

    Hope my advice could be helpful.

    Best regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by John6272 Sunday, February 10, 2019 4:08 PM
    Wednesday, January 23, 2019 1:35 AM
  • thanks for reply, but i solved my problem.
    Wednesday, January 23, 2019 3:37 AM
  • Hi John6272,

    Thanks for your feedback.

    Is your problem solved? If so, please post "Mark as answer" to the appropriate answer , so that it will help other members to find solution quickly if they faces similar issue.

    Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 29, 2019 8:28 AM