从c#控制台中运行SharePoint STSADM命令

本文关键字:SharePoint STSADM 命令 运行 控制台 | 更新日期: 2023-09-27 17:49:43

我被要求在c#中运行以下命令:

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

代码如下:

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

该命令在独立命令窗口中运行良好,但在控制台应用程序中运行时总是显示标准的"STSADM -o"帮助文本。

知道为什么吗?

gl-copylist命令是标准SharePoint STSADM命令的加载项。这就是原因吗?其他标准的STSADM命令在我的代码中运行。

从c#控制台中运行SharePoint STSADM命令

似乎在stsadm汇编中解析/验证命令行参数的方法中存在错误,特别是当接受值的includedescendants参数在之前指定时,发生以下错误:

命令行错误。

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

includedescendants参数指定为最后一个时,命令执行成功:

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