Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am new to coding. Started creating my 1st windowsservice to zip files from a certain location please review this code
The zip file is not created in the appropriate location of output folder in path2.

Please help me in this regard also attaching the logs at the end..
Please help need assistance from you guys

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.IO;
using System.Timers;
using ICSharpCode.SharpZipLib.Core;
using ICSharpCode.SharpZipLib.Zip;


namespace WindowsServiceZip
{
    public partial class WindowsServiceZip : ServiceBase
    {
        Timer timer;
        string path1 = @"D:\Zipped_Files\New_Text_Document.txt";
        string path2 = @"D:\output\filezipname.7z";
        string path3 = @"D:\Zipped_Files\R_23122015.txt";


        int timerInterval = 60000;

        public WindowsServiceZip()
        {
            InitializeComponent();
            timer = new Timer();
            timer.Elapsed += new ElapsedEventHandler(this.timer_Elapsed);
            timer.Interval = timerInterval;
            timer.Enabled = true;

        }

        protected override void OnStart(string[] args)
        {
            timer.Start();
        }

        protected override void OnStop()
        {
            timer.Stop();
            timer.SynchronizingObject = null;
            timer.Elapsed -= new ElapsedEventHandler(this.timer_Elapsed);
            timer.Dispose();
            timer = null;


        }
        public void timer_Elapsed(object sender, ElapsedEventArgs e)
        {

            ZipFile z = ZipFile.Create(path2);       //(filezipname);
            z.BeginUpdate();
            z.Add(path1);
            z.Add(path3);
            z.CommitUpdate();
            z.Close();


        }
    }
}


After running vs developer cmd prompt and installing in installutil.exe windowsservicezip.exe i am getting the following log file but zip is not getting created

Running a transacted installation.

Beginning the Install phase of the installation.
See the contents of the log file for the D:\vs_wpf\WindowsServiceZip\WindowsServiceZip\bin\Debug\WindowsServiceZip.exe assembly's progress.
The file is located at D:\vs_wpf\WindowsServiceZip\WindowsServiceZip\bin\Debug\WindowsServiceZip.InstallLog.

The Install phase completed successfully, and the Commit phase is beginning.
See the contents of the log file for the D:\vs_wpf\WindowsServiceZip\WindowsServiceZip\bin\Debug\WindowsServiceZip.exe assembly's progress.
The file is located at D:\vs_wpf\WindowsServiceZip\WindowsServiceZip\bin\Debug\WindowsServiceZip.InstallLog.

The Commit phase completed successfully.

The transacted install has completed.
Posted
Updated 31-Aug-15 16:57pm
v3

1 solution

Check whether the service is running with admin privileges so it can access this folder and write a zip in it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900