从SharePoint以编程方式运行.EXE

时间:2014-09-11 21:41:27

标签: c# sharepoint

是否可以使用SharePoint 2013 Project WebPart /计时器作业中的C#执行CMD命令?

我尝试了以下内容:

string commonFilesPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.System);
ProcessStartInfo proc = new ProcessStartInfo();
proc.FileName = commonFilesPath + "\\cmd.exe";
proc.WindowStyle = ProcessWindowStyle.Maximized;

proc.Arguments = "/C cd C:\\Folder && ftpclient.exe -area=SomethingThatCanChange -login=**** -password=***** -exitonupload";

using (Process exeProcess = Process.Start(proc)){
   exeProcess.WaitForExit();
}

在Sharepoint项目之外 - 我已经在Web Forms项目中进行了测试 - 这非常有效。部署到SharePoint时,请不要。没有例外。

我必须使用sharepoint列表中的值定期执行.exe文件(ftpclient.exe)。我该怎么办?

1 个答案:

答案 0 :(得分:0)

如果您打算按计划调用此.exe,则应在SharePoint之外运行整个过程。外部应用程序可以使用客户端对象模型(CSOM)或使用REST API与SharePoint列表进行交互。然后,您可以使用Windows任务计划程序根据需要运行它。

http://msdn.microsoft.com/en-us/library/office/fp179912(v=office.15).aspx#BasicOps_SPListItemTasks

如果您必须在SharePoint中运行此操作,请确保您使用的是完全信任解决方案,而不是Sandbox解决方案。