[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

Getting local physical path from IIS Virtual outside of ASP.Net

Rick Strahl

10/6/2003 3:50:00 AM

Hi all,

I'm working on some project management stuff that requires creating a new
project in VS.Net. I have the following issue though:

I can only retrieve hte project path as a URL (ie.
http://localhost/someproject) but I need to turn this back into a physical
path I can work with.

I can use DirectoryServices and IISAdmin paths to guess but this won't be a
foolproof way to map this out because it would be very difficult to figure
out the Web site ID if it's not the default site.

Anybody know a reliable way to do this, or even better as part of the
LaunchWizard method to retrieve the physical path?

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west...
http://www.west...wwHelp
----------------------------------
Making waves on the Web



3 Answers

David Levine

10/6/2003 11:42:00 PM

0

Here's some code that will retrieve the current physical path that a given
virtual directory is mapped to...

using System.DirectoryServices;

private string GetLocalPathForVDir(string strVDir)
{
try
{
if(strVDir != "" && DirectoryEntry.Exists(strVDir))
{
DirectoryEntry de = new DirectoryEntry(strVDir);
if(de.SchemaClassName == "IIsWebVirtualDir")
return (string)de.Properties["Path"].Value;
}
}
catch(Exception ex)
{
MessageBox.Show(this,"Error getting virtual directory path...incorrect
machine name?\n" + ex.Message );
}
return string.Empty;
}

I'm not quite sure if this is what you are looking for - what is the
LaunchWizard you are referring to? Are you using the EnvDTE interface to
Visual Studio to create the project?



"Rick Strahl [MVP]" <rickstrahl@hotmail.com> wrote in message
news:u3Tb4z7iDHA.2388@TK2MSFTNGP10.phx.gbl...
> Hi all,
>
> I'm working on some project management stuff that requires creating a new
> project in VS.Net. I have the following issue though:
>
> I can only retrieve hte project path as a URL (ie.
> http://localhost/someproject) but I need to turn this back into a physical
> path I can work with.
>
> I can use DirectoryServices and IISAdmin paths to guess but this won't be
a
> foolproof way to map this out because it would be very difficult to figure
> out the Web site ID if it's not the default site.
>
> Anybody know a reliable way to do this, or even better as part of the
> LaunchWizard method to retrieve the physical path?
>
> +++ Rick ---


Rick Strahl

10/8/2003 2:58:00 AM

0

Hi Dave,

> I'm not quite sure if this is what you are looking for - what is the
> LaunchWizard you are referring to? Are you using the EnvDTE interface to
> Visual Studio to create the project?

Yeah, that's it exactly. Basically I need to copy a custom template to the
users choice. Problem is EnvDte doesn't copy subdirectories and I need to
copy one <g> (an admin directory).

I couldn't get your code to run, BTW, but i have something similar that
assumes the default site. Problem is that if it's not hte default site.

When I run your code .Exists fails when I pass my VDir. What format shoudl
this be in? I used ("wwWebStore") or ("/wwWebStore") neither of which worked
even though this is a site on the local serrver default site.

Thanks for your help,

+++ Rick ---


--

Rick Strahl
West Wind Technologies
http://www.west...
http://www.west...wwHelp
----------------------------------
Making waves on the Web


"Dave" <noSpamdlevineNNTP2@wi.rr.com> wrote in message
news:eQ#HZMGjDHA.1672@TK2MSFTNGP09.phx.gbl...
> Here's some code that will retrieve the current physical path that a given
> virtual directory is mapped to...
>
> using System.DirectoryServices;
>
> private string GetLocalPathForVDir(string strVDir)
> {
> try
> {
> if(strVDir != "" && DirectoryEntry.Exists(strVDir))
> {
> DirectoryEntry de = new DirectoryEntry(strVDir);
> if(de.SchemaClassName == "IIsWebVirtualDir")
> return (string)de.Properties["Path"].Value;
> }
> }
> catch(Exception ex)
> {
> MessageBox.Show(this,"Error getting virtual directory path...incorrect
> machine name?\n" + ex.Message );
> }
> return string.Empty;
> }
>
> I'm not quite sure if this is what you are looking for - what is the
> LaunchWizard you are referring to? Are you using the EnvDTE interface to
> Visual Studio to create the project?
>
>
>
> "Rick Strahl [MVP]" <rickstrahl@hotmail.com> wrote in message
> news:u3Tb4z7iDHA.2388@TK2MSFTNGP10.phx.gbl...
> > Hi all,
> >
> > I'm working on some project management stuff that requires creating a
new
> > project in VS.Net. I have the following issue though:
> >
> > I can only retrieve hte project path as a URL (ie.
> > http://localhost/someproject) but I need to turn this back into a
physical
> > path I can work with.
> >
> > I can use DirectoryServices and IISAdmin paths to guess but this won't
be
> a
> > foolproof way to map this out because it would be very difficult to
figure
> > out the Web site ID if it's not the default site.
> >
> > Anybody know a reliable way to do this, or even better as part of the
> > LaunchWizard method to retrieve the physical path?
> >
> > +++ Rick ---
>
>


David Levine

10/9/2003 12:41:00 AM

0


>
> I couldn't get your code to run, BTW, but i have something similar that
> assumes the default site. Problem is that if it's not hte default site.
>
> When I run your code .Exists fails when I pass my VDir. What format shoudl
> this be in? I used ("wwWebStore") or ("/wwWebStore") neither of which
worked
> even though this is a site on the local serrver default site.
>
> Thanks for your help,
>

The path must be in the form "IIS://localhost/W3SVC/1/ROOT/VirtualDirPath"
where VirtualDirPath is the name of your local directory, such as
"MyRootDir/My1stSubDir/MyLastSubDir". In your case it would be
"IIS://localhost/W3SVC/1/ROOT/wwWebStore". Make sure you use a forward slash
to delimit path elements and not a backslash.

You should be able to google up some samples easily enough.