SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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
up vote 0 down vote accepted

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);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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