Run exe from Sharepoint web part
I have a button in a sharepoint we开发者_JS百科b part that when clicked is supposed to launch the calculator:
protected void Button1_Click(object sender, EventArgs e)
{
Process process = new Process();
process.StartInfo = new ProcessStartInfo("Calc.exe");
process.Start();
}
However, when the button is clicked, nothing happens. Can someone tell me how to launch applications from a sharepoint web part?
Quite frankly this is not possible. The code you have written is executed on the SharePoint server in the security context of the web app user. So if anything happens at all, a calculator is opened for the web app user and certainly not for your user.
If you want to do something like this you have to revert to client side scripting technologies, e.g. Silverlight
or JavaScript
. However, you have to deal with permission issues then as scripts normally can't access the local hard disk to improve security.
This is highly unadvisable to run executables from a web page, as this requires you to lower the browser security settings to such a level that could endanger the client PC, as pretty much any software can be downloaded and executed, without the user even knowing that. As pointed out in the earlier answer, the code you wrote will run the calculator on the server, not the client. It works on your dev machine because it is both server AND client, this will not work in the real world. The only way to do it is using some client side code, such as Javascript or Silverlight, but I would not recommend that. The best alternative would be adding a browser-hosted calculator directly to your web part, such as one using jQuery: the first search result: http://keith-wood.name/calculator.html
精彩评论