Running external zip utility - command line error

I’ve been attempting to launch a zip utility from C#.NET code.  Unfortunately, the 7-Zip utility that I’m using doesn’t like the command line string that I’m passing in.  Without getting into the switch syntax for this utility, I can tell you that the command line in the code below works when the utility is launched from the command prompt, so no problem there.

Here’s the sample code:

using System.Diagnostics;

private void btnZipMe_Click(object sender, System.EventArgs e)
{
    string strCmdLine = @"7z a -tzip c:\backups\schoolname.zip \a\*.doc";        
    ProcessStartInfo psi = new ProcessStartInfo();

    psi.FileName = @"C:\Program Files\7-Zip\7zG.exe";
    psi.Arguments = strCmdLine;
    Process p = Process.Start(psi);
}

When the last line of code above executes, the external utility pops up a message box stating “Incorrect command line” . Additionally, just as a test, I also set up everything under my C: drive to avoid escape characters even though the literal symbol should handle that – same error. Any ideas?

Thanks,
Tom
tmccallisterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ositearCommented:
watch out for the \ escaping \. I mean use \\ instead of \

bye
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
Shot in the dark...

Try setting the Working directory and starting it this way:

        Process p = new Process();
        p.StartInfo.FileName = @"C:\Program Files\7-Zip\7zG.exe";
        p.StartInfo.Arguments = @"7z a -tzip c:\backups\schoolname.zip \a\*.doc";
        p.StartInfo.WorkingDirectory = @"C:\Program Files\7-Zip\";
        p.Start();
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Expert1701Commented:
And another run at it...

  private void btnZipMe_Click(object sender, System.EventArgs e)
  {
    ProcessStartInfo psi = new ProcessStartInfo();
    psi.FileName = @"C:\Program Files\7-Zip\7z.exe";
    psi.Arguments = @"a -tzip ""c:\backups\schoolname.zip"" ""c:\FULL_PATH\a\*.doc""";
    Process p = Process.Start(psi);
  }
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.