Friday, November 30, 2007

SharePoint 2007 : How To Run STSADM Command From Your Code

Today, I've discovered something very interesting I want to share with you: How to run stsadm command inside my code. It's really easy, if you look at the following code, I specify to search from a membership provider only:
string prgFilePath = System.Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles); string stsadmPath = prgFilePath + @"\Microsoft Shared\web server extensions\12\BIN\stsadm.exe"; System.Diagnostics.Process proc = new System.Diagnostics.Process();
//Wait for the end of the process
proc.EnableRaisingEvents = false; proc.StartInfo.FileName = stsadmPath; proc.StartInfo.Arguments = "-o setproperty -url http://dcmoss:50020/ -pn "peoplepicker-nowindowsaccountsfornonwindowsauthenticationmode" -pv yes"; proc.Start();
//Wait
proc.WaitForExit();
With this method you can dynamically activate or deactivate feature, make some maintenance operation, change properties...

1 comment:

AI said...

Thank you very much!
Works like a charm ... ;-)

I created a helper method that is called executeStsadm.

AI