1

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.

Niranjan Godbole
  • 2,135
  • 7
  • 43
  • 90
  • Please clean up your question, unless you really meant that your startpath variable contains the following text at the end: " and zippath is C:\Neenu\Download.". – Lasse V. Karlsen Mar 23 '17 at 09:01
  • Use the stratpath as directory instead of file name `string startpath = @"C:\Users\spfarm\AppData\Local\\Temp\1neplbgk.qj3\";` – Thiru Mar 23 '17 at 09:04
  • Also set the zippath as a file name instead of directory `string zippath = @"C:\Test\Sample.zip";` – Thiru Mar 23 '17 at 09:07
  • Thank you. Actually I want to zip the entire folder 1neplbgk.qj3 inside the download folder. Message = "Access to the path 'C:\\Neenu\\Download' is denied." I got this meesage now. – Niranjan Godbole Mar 23 '17 at 09:08
  • 1
    Please post a [mcve] to ensure we can see exactly the code you are using. – Lasse V. Karlsen Mar 23 '17 at 09:09

1 Answers1

0

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:\result.zip";

        ZipFile.CreateFromDirectory(startPath, zipPath);
}
Community
  • 1
  • 1
pijemcolu
  • 2,257
  • 22
  • 36