Wondering if someone knows how to add a directory/folder to the web applications folder within IIS using a feature event receiver (FeatureActivated).

Any help appreciated.

  • Do you mean an application directory or virtual host within IIS, or a folder within a SharePoint site collection? – Daniel Symonds-Lloyd May 10 '12 at 22:58
  • application directory within iis... – MikeC May 11 '12 at 3:05
  • What is the purpose of using an application directory, is it for a custom web application (repeatable process) or some other file serving needs? Seeing this is a web server configuration change, I would not be recommending it through an event receiver. – Daniel Symonds-Lloyd May 11 '12 at 10:17
  • a third party control i am using needs a temp directory in the web apps virtual directory.....just trying to automate so i don't have to ask the client to do anything. :) – MikeC May 11 '12 at 14:55

Figured it out. In the Feature receiver i used the following code to get the virtual path to the webapplication and then create a directory. Never know if someone else will use it :)

string path = webApp.GetIisSettingsWithFallback(SPUrlZone.Default).Path.ToString();

            Directory.CreateDirectory(path + "\\Temp");
        catch (Exception ex) 
            // Get the local instance of the diagnostics service
            SPDiagnosticsService diagService = SPDiagnosticsService.Local;
            // Log the event under the SharePoint Foundation, Web Part category
            SPDiagnosticsCategory diagCategory = diagService.Areas["SharePoint Foundation"].Categories["Web Parts"];
            // The exception message to write to the log
            string exceptionId = "Web Part Exception Unique ID: " + Guid.NewGuid().ToString();
            string exceptionMsg = exceptionId + " " + ex.Message + ex.StackTrace;

            // Log the event as unexpected
            diagService.WriteTrace(0, diagCategory, TraceSeverity.Unexpected, exceptionMsg);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.