Run SharePoint STSADM command from C# Console

297 views Asked by At

I've been asked to run the following command from C#:

stsadm -o gl-copylist -sourceurl "http://someurl" -targeturl "http://someurl" -includeusersecurity -haltonfatalerror -deletesource -includedescendants All –nofilecompression

Here is the code:

ProcessStartInfo startInfo = new ProcessStartInfo()
{
    WindowStyle = ProcessWindowStyle.Normal,
    FileName = "cmd.exe",
    Arguments = "/C " + command,
    CreateNoWindow = true,
    UseShellExecute = false,
    RedirectStandardError = true,
    RedirectStandardOutput = true
};

The command runs fine in a stand-alone command window, but always displays the standard "STSADM -o" help text when run from my console app.

Any idea why??

The gl-copylist command is an add-in to the standard SharePoint STSADM command. Could this be the reason? Other standard STSADM commands run in my code.

1

There are 1 answers

0
Vadim Gremyachev On

It seems there is an error in method that parses/validates command line arguments in stsadm assembly, in particular when includedescendants parameter that accepts value is specified before another parameter the following error occurs:

Command line error.

stsadm -o gl-copylist 
-sourceurl "http://server/sourceweb/listviewpage" 
-targeturl "http://server/targetweb" -includeusersecurity 
-haltonfatalerror 
-deletesource 
-includedescendants All   <- when this parameter is specified before another parameter    
–nofilecompression

Once the includedescendants parameter is specified as the last one, the command is executed successfully:

stsadm -o gl-copylist 
-sourceurl "http://server/sourceweb/listviewpage" 
-targeturl "http://server/targetweb" -includeusersecurity 
-haltonfatalerror 
-deletesource 
–nofilecompression
-includedescendants All