Niranjan Godbole Niranjan Godbole -4 years ago 117
C# Question

Unable to zip folder in c#

Hi I am trying to create a zip folder in c#.

This is my destination where I need to have my zip.
string zippath = @"C:\Neenu\Download";
Below is my code to convert it as ZIP.

ZipFile.CreateFromDirectory(@"" + startPath, @"" + zippath);

My start path is

C:\\Users\\spfarm\\AppData\\Local\\Temp\\1neplbgk.qj3\\ilty Management System -SCM-2016-39.docx

I am getting error as access to path is denied.
Any help would be appreciated. Thank you.

Answer Source

This could be a complete example of how to compress a file using your code, you should clean up your variables and make sure that your paths are correct.

When it comes to accessing your C drive, there might be a permission problem, in that case you could try to run the program as administrator in order to get full (read/write depends on your needs) access to the drive as specified here

using System;
using System.IO;
using System.IO.Compression;    

static void Main(string[] args)
        string startPath = @"C:\Users\spfarm\AppData\Local\Temp
                             \1neplbgk.qj3\ilty Management System -SCM-2016-39.docx";
        string zipPath = @"c:\";

        ZipFile.CreateFromDirectory(startPath, zipPath);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download