Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Need to create a windows service app to ZIP a text file from a predefined location & store it n a database. I have to do this in Vs2008 & framework3.5 environment. I am a novice in using "windows services" . I am trying to add "DotnetZip" library & add reference "iconic.zip" to my app. But after adding reference also I am not getting "Using Iconic.zip" in my .cs file as shown in many examples. Please help me in solving this issue by sharing valuable suggestions & code.
Posted

Use SharpZipLib(Open Source), you get many working examples there too from their samples.
http://www.icsharpcode.net/OpenSource/SharpZipLib/[^]
 
Share this answer
 
Comments
sri67 12-Aug-13 7:36am    
@Kuthuparakka .. Thank you Sir. I have tried & able to derive "ICSharpCode.SharpZipLib.Zip" class in my code & coded the required thing. But i am unable to convert a file from predefined location using "windows services" after installing in my system. Can you please specify "Usage: CreateZipFile Path ZipFile" this format while coding? I guess my error lies here only.
Kuthuparakkal 12-Aug-13 7:39am    
Please check the account under service is running has permission to access the file to be zipped
sri67 12-Aug-13 7:47am    
Yes sir.. I changed the service to 'local system' & this has permission to run windows services.
Kuthuparakkal 12-Aug-13 8:38am    
Does "Local System" have permission to access your files/folders ?
sri67 12-Aug-13 10:20am    
Yes I registered other services (basic code depending on Timers & schedules which operates on text files) by using "local system" only!!
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 trail2zip
{
    public partial class trail2zip : ServiceBase
    {
        Timer timer;
        string path1 = @"E:\zipped files\New Text Document.txt";
        string path2 = @"E:\output\filezipname.zip";
        string path3 = @"E:\zipped files\R_23122015.txt";


        int timerInterval = 60000;

        public trail2zip()
        {
            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();


        }
    }
}

the above code is successfully zipping a text file from a predefined folder location. Now i want to modify this code in such a way that 'any file in the folder if found (giving the name of text file in run time)the data should be uploaded & it should be zipped, & the old file should be deleted. I can do this if i dont have runtime text file names, but doing the same in run time.. hope someone will help me with this.
 
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