I got an interesting email the other day from Chakir Said regarding a bug that he encountered with SharePoint. He mis-typed the folder path for the web application and unfortunately the UI page has no validation to make sure that a valid path was specified. The result was that a web application was partially created and the invalid path was preventing the web application from being deleted – any attempts to delete would result in the error “Absolute Path Information Requried”. This is because the get accessor of the Path property of the SPIisSettings object does a FileIOPermission check on the path which fails with the invalid (the set accessor does not do this check so it allows an invalid path to be set). Fortunately the fix turned out to be pretty simple – just set the Path property so something known and then call update on the web application. I’ve included the core code below (assumes you already have webApp set to the SPWebApplication
object in question):
1foreach (SPIisSettings iis in webApp.IisSettings.Values)
2{
3 try
4 {
5 DirectoryInfo path = iis.Path;
6 if (!path.Exists)
7 throw new Exception();
8 }
9 catch (Exception)
10 {
11 iis.Path = new DirectoryInfo("c:\\");
12 webApp.Update();
13 }
14}
For the code above I’m simply setting the path to something that I know will exist if the current path is invalid, the root C:\ drive. This code could easily be ran on it’s own (with the code to get the SPWebApplication
object) or included in a custom delete command – which fortunately I have a custom deletewebapp
command which I’ve updated to include this fix. Note that I also have a new command “gl-unextendwebapp” which handles the case in which a web application was extended using an invalid path. This new command is available in the download but not yet documented.