I am trying to compress files with GZIP and my application monitors a folder for new files. When a new file comes in, it should be compressed and then application should continue doing this every time a new file comes in folder.
private void Compress(string filePath)
{
using (FileStream inputStream = new FileStream(filePath,FileMode.OpenOrCreate,FileAccess.ReadWrite))
{
using (FileStream outputStream = new FileStream(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"C:\\Users\\maki\\Desktop\\Input"), FileMode.OpenOrCreate, FileAccess.ReadWrite))//'System.UnauthorizedAccessException'
{
using (GZipStream gzip = new GZipStream(outputStream, CompressionMode.Compress))
{
inputStream.CopyTo(gzip);
}
}
}
}
when I execute the application, I get this exception:
An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
Additional information:
Access to the path 'C:\Users\maki\Desktop\Input' is denied.
I've searched a lot in internet but couldn't find a proper answer.
Can anyone help me with issue?