Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
the below 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.
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();
 

        }
    }
}
Posted
Updated 25-Dec-13 22:20pm
v2

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