c# robocop code is not working

This is a continuation of previous question, window opens, quickly  closes and newer files are NOT copied. No error is displayed, I have tried several different argument types

example
startInfo.Arguments = "\\SOURCE @\\SERVERNAME\\FOLDER /xo /s /Z /W:5";

All attempts have ended with no error and no newer files copied from USB.
 

I have added
using System.Diagnostics;



ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.FileName = "robocopy.exe";
                startInfo.WorkingDirectory = "E:";  //USB Drive Letter
                startInfo.Arguments = "\\SOURCE" + @"\\SERVER\\FOLDER  /xo /s /Z /W:5";                     //source  & destination
                startInfo.UseShellExecute = false;
                startInfo.CreateNoWindow = true;
                startInfo.RedirectStandardError = true;
                startInfo.RedirectStandardOutput = true;
                Process p = Process.Start(startInfo);
                string errors = p.StandardError.ReadToEnd();
                string output = p.StandardOutput.ReadToEnd();
                p.WaitForExit();
                Resultlabel.Text = ("Backup Complete");
jlspencerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

WilliamCommented:
Robocopy requires elevated privileges - the work around I use is below.
 
Please try the following
 if ( System.Environment.OSVersion.Version.Major >= 6 )
  {
        startinfo.Verb = "runas";
  }
  p.Start();

Open in new window

jlspencerAuthor Commented:
Thank you BillyDVD I hope this works, as I am still new to programming where do I insert this code?
WilliamCommented:
if ( System.Environment.OSVersion.Version.Major >= 6 )
  {
        startinfo.Verb = "runas";
  }
  p.Start();
p.WaitForExit();
Resultlabel.Text = ("Backup Complete");

Open in new window

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

it_saigeDeveloperCommented:
Just pointing out another issue.

The '@' symbol is used to turn your string into a literal.  It tells the compiler; everything that follows me is *literally* a part of the string I want to output.

To put it another way:
using System;

namespace EE_Q28756300_StringLiteral
{
	class Program
	{
		static void Main(string[] args)
		{
			string str1 = "This string contains a few characters that would normally need to be escaped in order to print - \\ & \"";
			string str2 = @"This string contains a few characters that would normally need to be escaped in order to print - \ & """;
			Console.WriteLine(str1);
			Console.WriteLine(str2);
			Console.WriteLine("Are str1 and str2 equal? {0}", str1 == str2);
			Console.ReadLine();
		}
	}
}

Open in new window

Produces the following output -Capture.JPG
My reasoning for pointing this out:
startInfo.Arguments = "\\SOURCE" + @"\\SERVER\\FOLDER  /xo /s /Z /W:5";                     //source  & destination

Open in new window

While this is all well and good, it seems as if you are trying to point to a couple of network locations.  If this is true then you need to ensure that you are using the correct path; e.g. - \\<servername>\<sharename>.

So your line needs to reflect this (also don't forget about applying the string literal character or properly escaping your backslashes); e.g. -
// Maybe you meant this
startInfo.Arguments = @"\\SOURCE \\SERVER\FOLDER  /xo /s /Z /W:5";                     //source  & destination
// Or maybe you meant this
startInfo.Arguments = @".\SOURCE \\SERVER\FOLDER  /xo /s /Z /W:5";                     //source  & destination

Open in new window


-saige-

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
jlspencerAuthor Commented:
Here is the bulk of code that finally worked with out any errors:

Thank you saige for pointing out the error in my code, now I can continue to develop this and prompt for user input strings.
 
Resultlabel.Text = ("Ok to backup files");
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.WorkingDirectory = "F:";  //USB Drive Letter
                startInfo.FileName = "robocopy.exe";
                startInfo.Arguments = @"\docs \\server\data\home\userid\docs /xo /s /Z /W:5";
                startInfo.UseShellExecute = false;
                startInfo.CreateNoWindow = true;
                startInfo.RedirectStandardError = true;
                startInfo.RedirectStandardOutput = true;
                Process p = Process.Start(startInfo);
                string errors = p.StandardError.ReadToEnd();
                string output = p.StandardOutput.ReadToEnd();
                p.WaitForExit();
                Resultlabel.Text = ("Backup Complete");
jlspencerAuthor Commented:
Thank you to all that provided feedback, while I could not get some of the provided solutions to work that is probably due to my inexperience in writing code. Your time was much appreciated.
jlspencerAuthor Commented:
This worked for the demo
startInfo.Arguments = @"\docs \\server\data\home\userid\docs /xo /s /Z /W:5";

However the actual folder name has spaces in it

This does not back up the files

startInfo.Arguments = @"\docs for server   \\server\data\home\userid\docs /xo /s /Z /W:5";
jlspencerAuthor Commented:
I have discovered that this code works but it requires that users will need to remove spaces from parent folder name...

startInfo.Arguments = @"\docs_for_server   \server\data\home\userid\docs_for_server /xo /s /Z /W:5";

Is there a way to get this to work leaving spaces in the parent folder name?
WilliamCommented:
You have to wrap each path in quotes in the argument so you need:
string arg = "\"\\docs_for_server   \\server\\data\\home\\userid\\docs_for_server /xo /s /Z /W:5\"";

The reason is - the argument will get cut into pieces at the space and become at least 3 different arguments that will fail
\docs_for_server
server\data\home\userid\docs_for_server
 /xo /s /Z /W:5\
jlspencerAuthor Commented:
William would that work for both spaced and non spaced folders?
WilliamCommented:
Yes - When I run robocopy via code bass - I always wrap the strings - needed or not -
You can test this out by running a batch file or command prompt, with and without the quotes to see the failure.
jlspencerAuthor Commented:
That did it !! Thank you William you are a blessing
WilliamCommented:
jLspencer - Giving an assist would be nice :)
jlspencerAuthor Commented:
Not sure how to do the ASSIST I do not see any link to do that let me know and I will.

I spoke to soon on the app working, it does work for me on the local network however the intended user who is on a DMVPN site ( he can read and write to the server at my location) but the app does not attempt to save the updated files at all. There is no error, app indicates it completed.
WilliamCommented:
On the DMVPN site - Are you using host name (\\MYSERVER\SomeShare\Dir)?
If so - Check if you can ping the intended server by name. If that works, I would go back to my original response - It needs elevated privileges. If it does not work - try replacing "MYSERVER" with the IP address( \\192.168.1.168\SomeShare\Dir). If that works - then you likely have a dns issue.  This would be a separate issue from the robocopy.

Check this out and see if this helps :)
http://support.experts-exchange.com/customer/en/portal/articles/608596-how-do-i-accept-multiple-comments-as-my-solution-?b_id=44
jlspencerAuthor Commented:
It appears that it is to late to un-accept the contributors solution I will open another ticket and award point to you...as this issue continues,
WilliamCommented:
Thanks jlspencer - and post the link to the new question when you have it up.
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.