Click here to Skip to main content
15,353,970 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my UnRAR a file code,its not working when there is space in the path(eg:D:\UnRAR File\Files).if there is no space(eg:D:\UnRARFile\Files) i can able to unrar.

so someone plz help me...

C#
string the_Info;

            ProcessStartInfo the_StartInfo;
            Process the_Process;
            try
            {
                string path = @"" + fstrpath + "";
                string RarFile_dir = "";

                RarFile_dir = @"" + fstrpath + "\\" + fstrRarFileName + "";

                // if unRAR files exist delete it
                if (Directory.Exists(RarFile_dir) == true)
                    Directory.Delete(RarFile_dir, true);

                the_Info = " X " + path + "\\" + fstrRarFileName + ".rar " + " " + path;
                the_StartInfo = new ProcessStartInfo();

                the_StartInfo.FileName = path + "\\winRAR.exe";
                the_StartInfo.Arguments = the_Info;
                the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                the_StartInfo.WorkingDirectory = path;
                the_Process = new Process();
                the_Process.StartInfo = the_StartInfo;
                the_Process.Start();
                the_Process.WaitForExit();
                the_Process.Close();
                RarFile_dir = @"" + path + "";
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
Posted
Updated 3-Dec-12 0:11am
v3

1 solution

If you're constructing an argument list for an external executable, for instance, all you have to do is quote the path:

C#
string path = @"C:\TestFolder\Input\Some File.rar";
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "program.exe";
psi.Arguments = "\"" + path + "\""; // escape the quotes


..which will result in this commandline:

program.exe "C:\TestFolder\Input\Some File.rar"
   
Comments
AmitGajjar 3-Dec-12 7:34am
   
Correct 5+
Mendor81 3-Dec-12 8:46am
   
Thanks

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