This project is read-only.

Not working in Windows Service.

Oct 4, 2016 at 8:12 AM
I've used this to create password protected zip file in the windows service. When I deploy the service on the server it gives error "could not find a part of the path C:\Windows\System32\TEmp\" on zip.Save() line. I set below property to overcome this problem.

zip.TempFileFolder = applicationPath + "\Temp";

The path given above is the valid one and service has all permission (read, write) to this path. Still zip.Save() is giving me "could not find a part of the path" error.

Any help would be appreciated.

Thanks in advance.
Nov 24, 2016 at 3:10 PM
Edited Nov 24, 2016 at 3:26 PM
I would suggest your path is wrong.

zip.TempFileFolder = applicationPath + "\Temp";

"\temp" - the first two characters "\t" are escape sequence for a tab character, so you're actually getting:
zip.TempFileFolder = applicationPath + "<tab character>emp";

try either:

zip.TempFileFolder = applicationPath + @"\Temp";
zip.TempFileFolder = applicationPath + "\Temp";

or better yet: zip.TempFileFolder = Path.Combine(applicationPath + @"\Temp");

Also, when running as a service, it will generally run as either: NETWORK SERVICE, LOCAL SERVICE, LOCAL SYSTEM or a named user if you impersonate a user's account login.
What I'm trying to say is you may have access to the path (read & write access) but the account the service is actually running as: NETWORK SERVICE (for example) may not. To check what your service is running as. Load: services.msc, find your service, and click on the "Log On" tab.