Problem with String[] Arrays


What the problem with the code below, the red part is complaining that
Argument '1': cannot convert from 'string[]' to 'string'
Why?

public static void Main(string[] args)
        {
            string[] FilesToBeZipped = { "C:\\zip\\Roger.doc", "C:\\zip\\Roger2.doc", "C:\\zip\\Roger3.doc" };
            RunZip(FilesToBeZipped, "Obinna.Zip");
        }
       

        public static void RunZip(string[] FilesToBeZipped, string ZipName)
        {
            ZipFiles(FilesToBeZipped,ZipName);
        }

        public static  void ZipFiles(string[] FilesToBeZipped, string ZipName)
        {
            string[] filenames = Directory.GetFiles(FilesToBeZipped);

            Crc32 crc = new Crc32();
            ZipOutputStream s = new ZipOutputStream(File.Create(ZipName));

            s.SetLevel(6); // 0 - store only to 9 - means best compression

            foreach (string file in filenames)
            {
                FileStream fs = File.OpenRead(file);

                byte[] buffer = new byte[fs.Length];
                fs.Read(buffer, 0, buffer.Length);
                ZipEntry entry = new ZipEntry(file);

                entry.DateTime = DateTime.Now;

                entry.Size = fs.Length;
                fs.Close();

                crc.Reset();
                crc.Update(buffer);

                entry.Crc = crc.Value;

                s.PutNextEntry(entry);

                s.Write(buffer, 0, buffer.Length);

            }

            s.Finish();
            s.Close();
        }   
0
obinna123
6/15/2006 9:57:19 AM
asp.net.getting-started 91979 articles. 3 followers. Follow

2 Replies
226 Views

Similar Articles

[PageSpeed] 34

Why are you using Directory.GetFiles

you already have the array (FilesToBeZipped).

public static  void ZipFiles(string[] FilesToBeZipped, string ZipName)
        {

         ////string[] filenames = Directory.GetFiles(FilesToBeZipped); - comment out
            Crc32 crc = new Crc32();
            ZipOutputStream s = new ZipOutputStream(File.Create(ZipName));

            s.SetLevel(6); // 0 - store only to 9 - means best compression

            foreach (string file in FilesToBeZipped)


Articles and news on ASP/ASP.NET
ASPCode.net
0
aspcode
6/15/2006 10:43:24 AM
FilesToBeZipped is an array and GetFiles only accepts a string.  So you can't pass an array to it.  Looking at what you're doing, I don't think you need GetFiles at all.  Instead of

foreach (string file in filenames)

use

foreach (string file in FilesToBeZipped)

0
Aidy
6/15/2006 10:46:18 AM
Reply: