bala_88
bala_88

Reputation: 391

Checking whether a folder exists under an IIS application using C#

I'm working on a web based deployment tool in C# which deploys applications remotely on IIS 7.

I've reached a point where where I'm able to deploy an application. Now I need to see if the application that is deployed has a a certain directory before attempting to set permissions on it (Since the tool would deploy different applications which may or may not have that folder).

There are two approaches that I took:

Upvotes: 3

Views: 2194

Answers (1)

bala_88
bala_88

Reputation: 391

For now, I have a workaround. I can use the WhatIf (set it true) property under DeploymentSyncOptions, do a sync and then check if an object got added. If it did, the directory does not exist. Code :

var syncOptions = new DeploymentSyncOptions();
syncOptions.WhatIf = true;

using (deploymentObject)
{
   var result = deploymentObject.SyncTo(
   DeploymentWellKnownProvider.SetAcl,
   "Default Web Site/path_to_folder",
   destinationBaseOptions,
   syncOptions);

   if (result.ObjectsAdded != 0)
   {
     syncOptions.WhatIf = false;
     deploymentObject.SyncTo(DeploymentWellKnownProvider.SetAcl,
                            "Default Web Site/path_to_folder",
                             destinationBaseOptions,
                             syncOptions);
   }
}

Upvotes: 1

Related Questions