BUG: Absolute Path Information Required

Posted on Posted in SharePoint 2007

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):

   1: foreach (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.

2 thoughts on “BUG: Absolute Path Information Required

  1. This is very useful information Gary, thanks. As a matter of interest, is there a reason why you are throwing an exception (it is an expensive operation)? Why not just execute the catch block code in the if block code?

  2. Because the property getter throws if the path is invalid and I didn’t want to have to add additional logic to handle that as well as the path not existing so it was easier to just throw and handle the bad path in one place (besides, the way this code will be used performance isn’t going to be a concern). Thanks for the feedback!

Leave a Reply

Your email address will not be published. Required fields are marked *