samedi 29 novembre 2014

run exe as process from sharepoint webpart



Im trying to run an exe file to create a contentdatabase and then create a sitecollection in this database, running this process is working well outside the sharepoint, but when im trying to run it from sharepoint it did nothing and no database creates.


this is my console app (exe file)



if (args != null)
{
string name = args[0];
string serverName = args[1];
SPWebApplication webApplication = SPWebApplication.Lookup(new Uri(args[2]));
SPContentDatabaseCollection dbc = webApplication.ContentDatabases;

var contentDatabase = new SPContentDatabase();
SPSecurity.RunWithElevatedPrivileges(delegate
{
contentDatabase = dbc.Add(
serverName,
"WSS_Content_" + name,
"",
"",
10,
20,
0);
contentDatabase.Update();
webApplication.Update();
});
}


and this im running in sharepoint webpart to run the exe file



SPSecurity.RunWithElevatedPrivileges(delegate
{
ProcessStartInfo pInfo = new ProcessStartInfo(@"C:\CreateContentdb");
pInfo.CreateNoWindow = false;
pInfo.UseShellExecute = false;

var arr = new string[] { name, dbServerName, webApplication.ToString() };
const string argsSeparator = " ";
string args = string.Join(argsSeparator, arr);
pInfo.Arguments = args;
Process.Start(pInfo).WaitForExit();







0 commentaires:

Enregistrer un commentaire