locked
Error - The Directory name is InValid RRS feed

  • Question

  • User-1499457942 posted

    Hi

      I have below lines

    string startPath = @"d:\PO.xls";
    string zipPath = @"d:\Po.zip";

    ZipFile.CreateFromDirectory(startPath, zipPath);

    Thanks

    Monday, June 11, 2018 10:42 AM

All replies

  • User475983607 posted

    JagjitSingh

      I have below lines

    string startPath = @"d:\PO.xls";
    string zipPath = @"d:\Po.zip";

    ZipFile.CreateFromDirectory(startPath, zipPath);

    Thanks

    You're not using the CreateFromDirectory method as documented.  You are supplying a source file name when the method docs clearly state the method is expecting a source folder.

    Please try reading the docs rather than making up you own idea how the method functions.

    https://msdn.microsoft.com/en-us/library/hh485707(v=vs.110).aspx

    Monday, June 11, 2018 10:51 AM
  • User-1499457942 posted

    Hi

     I have written this but still getiing same error 

    string zipPath = @"d:\Po\Po.zip";

    Thanks

    Monday, June 11, 2018 11:03 AM
  • User475983607 posted

    Hi

     I have written this but still getiing same error 

    string zipPath = @"d:\Po\Po.zip";

    Thanks

    Correct because you have not changed the source to a folder.  Please read the openly published documentation and see the sample code.

    using System;
    using System.IO;
    using System.IO.Compression;
    
    namespace ConsoleApplication
    {
        class Program
        {
            static void Main(string[] args)
            {
                string startPath = @"c:\example\start";
                string zipPath = @"c:\example\result.zip";
                string extractPath = @"c:\example\extract";
    
                ZipFile.CreateFromDirectory(startPath, zipPath);
    
                ZipFile.ExtractToDirectory(zipPath, extractPath);
            }
        }
    }

    Monday, June 11, 2018 11:12 AM
  • User-1499457942 posted

    Hi

     Still same problem

    string startPath = @"d:\PO\PO.xls";
    string zipPath = @"d:\PO\PO.zip";

    ZipFile.CreateFromDirectory(startPath, zipPath);

    Thanks

    Monday, June 11, 2018 11:22 AM
  • User475983607 posted

    Hi

     Still same problem

    string startPath = @"d:\PO\PO.xls";
    string zipPath = @"d:\PO\PO.zip";

    ZipFile.CreateFromDirectory(startPath, zipPath);

    Thanks

    I guess you do not know the difference between a file and a folder.  This is a file

    @"d:\PO\PO.xls";

    This is a folder.

    @"d:\PO";

    The method expects a source folder not a file.  Change the startPath to...

    @"d:\PO";

    and the method will zip everything in the PO folder as openly written in the reference documentation.

    Monday, June 11, 2018 11:38 AM
  • User-1499457942 posted

    Hi

      I gave startpath = "d:\po"  With this it is zipping all the files . i want to Zip single file

    Thanks

    Monday, June 11, 2018 12:16 PM
  • User475983607 posted

    Hi

      I gave startpath = "d:\po"  With this it is zipping all the files . i want to Zip single file

    Thanks

    Again, It is very helpful to read the documentation rather than making up your own syntax.

    One simple method to solve this problem is to create a folder and place inside the folder a single file.  You might need other logic to clean up the folder - not sure.

    Another solution is creating a zip archive and adding to the archive.

    https://msdn.microsoft.com/en-us/library/hh485720(v=vs.110).aspx

    Monday, June 11, 2018 1:32 PM