hi,

[I'm not quite sure where best to post this, as the question spans the IIS /
Asp.Net and the "scripting" or Console Application sides of the universe.
hope these 2 locations are appropriate.]

an Asp.Net page/script writes pictures to an "image cache", which is a
virtual directory, say "m" mapped to a real physical directory (or network
share), say c:\temp or ServerX : X$ \ media. this works fine. now, however,
i want to write a console application, scheduled to run once an hour, say,
which deletes pictures (files in the physical directory) older than, say, 4
hours.

this is all no problem. however, i'd like my machine.config application
settings to include the name of the virtual directory (so web and console
apps can both find it). web apps have no trouble mapping VirDir m to the
physical directory, but is there a way for a console application to do it?
(i have looked and googled, but not found what I need.)

is this a dumb idea? i'd rather not have to write the physical directory
name in machine.config (it varies wildly from developer machine to live
machine and can depend on other things too). i'd prefer all these machines
agreed on "m" and different places keep their physical locations (in their
IIS admin) where they want them.

i can write a web page to do this and then call it via http, but that seems
more than a bit klunky.

should i be thinking in terms of IIS administration scripting or the like?
(i have looked, but haven't yet found a good fit.) are there DotNet/C# tools
for scripting IIS6? (have looked...)

NB:
iisvdir /query mySite
is quite handy and delivers, among other things, the info I need. (so an
object that returned me the same information, say as a
dictionary<string,string> (VirDir mapping to PhysDir) would be great!)

i'd be grateful for any pointers.

cheers,

Tim Hanson

RE: calling (IIS) MapPath from a console application ? by v-yren

v-yren
Wed Jan 11 01:41:22 CST 2006

Hi Tim,

Welcome to MSDN newsgroup!

For your issue, I have performed a simple demo. The demo can display both
the Virtual Directory path and the Physical Directory path. The sample code
is as follows:
class Program
{
static void Main(string[] args)
{
Program p = new Program();
p.GetVirtualDirectories();
}

public void GetVirtualDirectories()
{
string serverName = "localhost";
string VirDirSchemaName = "IIsWebVirtualDir";
DirectoryEntry iisServer = new DirectoryEntry("IIS://" + serverName
+ "/W3SVC/1/Root");
DirectoryEntry folderRoot = iisServer.Children.Find("MySite",
VirDirSchemaName);
Console.WriteLine(folderRoot.Properties["Path"].Value.ToString());
Console.WriteLine(folderRoot.Path);
}
}

Please note, if you want to run the application, you need to add both the
DirecotrySerives reference reference and its namespace into the current
projecct.

I appreciate your understanding and hope the above information helps, if
you have any issues or concerns please let me know. I will be happy to be
of further assistance.

Regards,

Yuan Ren [MSFT]
Microsoft Online Support


Re: calling (IIS) MapPath from a console application ? by tbh

tbh
Wed Jan 11 09:19:28 CST 2006


""Yuan Ren[MSFT]"" <v-yren@microsoft.com> wrote in message
news:nmCk0JoFGHA.3764@TK2MSFTNGXA02.phx.gbl...
> Hi Tim,
>
> Welcome to MSDN newsgroup!
>
> For your issue, I have performed a simple demo. The demo can display both
> the Virtual Directory path and the Physical Directory path. The sample
> code
> is as follows:
...

thanks very much, Yuan. that helps a lot. i'll append the adaptation of your
test program i ended up with after exploring. i think i can figure out on my
own how to deal with the strange site IDs. (hmmm, I fear code pasting here
is possibly bad.)

thanks again,

Tim Hanson

class Program {

static void Main(string[] args) {

Program p = new Program();

p.GetVirtualDirectories("localhost");

p.GetVirtualDirectories("localhost/W3SVC");

p.GetVirtualDirectories("localhost/W3SVC/228814919");

p.GetVirtualDirectories("localhost/W3SVC/228814919/root");

p.GetVirtualDirectoryDetails("localhost/W3SVC/228814919/root", "m");

Console.Read();

}

public void GetVirtualDirectories(string serverNameAndPath) {

Console.WriteLine("----------------------");

Console.WriteLine(string.Format("GetVirtualDirectories({0})",
serverNameAndPath));

Console.WriteLine("----------------------");

DirectoryEntry iisServer = new DirectoryEntry("IIS://" + serverNameAndPath);

DirectoryEntries dirs = iisServer.Children;

foreach (DirectoryEntry dir in dirs) {

Console.WriteLine("dir.Path: " + dir.Path);

}

}

public void GetVirtualDirectoryDetails(string serverNameAndPath, string
VirDir) {

Console.WriteLine("----------------------");

Console.WriteLine(string.Format("GetVirtualDirectoryDetails({0}, {1})",
serverNameAndPath, VirDir));

Console.WriteLine("----------------------");

DirectoryEntry iisServer = new DirectoryEntry("IIS://" + serverNameAndPath);

string VirDirSchemaName = "IIsWebVirtualDir";

DirectoryEntry folderRoot = iisServer.Children.Find(VirDir,
VirDirSchemaName);

Console.WriteLine(folderRoot.Properties["Path"].Value.ToString());

Console.WriteLine(folderRoot.Path);

}


}




Re: calling (IIS) MapPath from a console application ? by v-yren

v-yren
Wed Jan 11 21:37:19 CST 2006

Hi Tim,

You are welcome! I'm glad to hear your issue has been resolved.If you have
any issues in the future, please feel you free to let me know. It's my
pleasure to be of assistance.

Regards,

Yuan Ren [MSFT]
Microsoft Online Support