using Server.MapPath in a windows application?

  • Thread starter Thread starter MrPolite
  • Start date Start date
M

MrPolite

I want to be able to use Server.MapPath in a windows application. I've added
the system.web reference to my project but whenever I try to call it, I get
a null reference error. Anyone can tell me how to use this function?
(this is how I'm calling it:
System.Web.HttpContext.Current.Server.MapPath() )
 
well I had another post where I was trying to figure out how to open a
VS.NET solution file, get the project file's path and then open the project
file with a streamReader. It turns out that when the project is an asp.net
project, its path always starts with http://localhost/ and that streamReader
cannot open a path like that. So I'm trying to figure out a way to convert
that path from localhost/whatever to the physical directory's path. I guess
thats the only way I can open the project file...
 
I responded to you, I said I want to figure it out using code not what you
said. The default webserver's location can be changed, it's not good to
assume a folder... I'm just trying to figure out the right way.
 
I thought you already had the answer ??? - it's stored in the registry.
HKLM\System\CurrentControlSet\Services\W3SVC\Parameters\Virtual Root Name =
"/"

Mike
 
Hi MrPolite

I'm with you on this one (sorry Cor). I posted a while ago with the same
question, but did not get a response at all, so I have been watching this
thread with interest.

In my registry I have

HKLM\System\CurrentControlSet\Services\W3SVC\Parameters\Virtual Roots

and not

HKLM\System\CurrentControlSet\Services\W3SVC\Parameters\Virtual Root Name

Perhaps a typo in Mike's post, but perhaps not, in which case, does it
change from one o/s to another?

Also, the entry in my registry reads

d:\inetpub\wwwroot,,201

Is this standard syntax, i.e. do I remove the trailing ,,201 (and what does
it signify), or not?

Furthermore, do we suppose that this is the way VS.NET and IIS do it? Like
you, I had imagined there would be a nifty .NET class that would just give
it to me.

Charles


MrPolite said:
well I had another post where I was trying to figure out how to open a
VS.NET solution file, get the project file's path and then open the project
file with a streamReader. It turns out that when the project is an asp.net
project, its path always starts with http://localhost/ and that streamReader
cannot open a path like that. So I'm trying to figure out a way to convert
that path from localhost/whatever to the physical directory's path. I guess
thats the only way I can open the project file...



I
 
Hi Charles,

In the original thread was in my eyes an unnecessary flaming answer on an
answer from me.

It seems to be not from Mr. Polite because another name was used.

He asked (to figure out in code) the hard disk from the "http:\\localhost".
Because such an question does not direct give the idea that the OP
understand the problem I did give the answer that the address of that was
127.0.0.1 and mostly C:\Inetpub.www

When he had asked if it was possible in code, to find the real disk address
of the starting root point of the standard virtual web server map, than I
had probably given another answer.

In this thread, I only asked this question to check if the flame was from
Mr. Polite, and it was.

When I was sure, I understand that "Mr. Polite" did not like my answers, so
I stopped with answering him..

So in my opinion, you don't have to say sorry for that, you probably did not
know this.

:-)

Cor
 
Charles,

I don't think it was a typo, this is from my machine running XP pro. I have
no idea what the ,,201 means. But what I did was open up the properties of
my default web site, changed the location of the path, then looked back to
see what was changed in the registry.

Sorry, don't know about other OS's, was just a quick look on my machine.

Mike


Charles Law said:
Hi MrPolite

I'm with you on this one (sorry Cor). I posted a while ago with the same
question, but did not get a response at all, so I have been watching this
thread with interest.

In my registry I have

HKLM\System\CurrentControlSet\Services\W3SVC\Parameters\Virtual Roots

and not

HKLM\System\CurrentControlSet\Services\W3SVC\Parameters\Virtual Root Name

Perhaps a typo in Mike's post, but perhaps not, in which case, does it
change from one o/s to another?

Also, the entry in my registry reads

d:\inetpub\wwwroot,,201

Is this standard syntax, i.e. do I remove the trailing ,,201 (and what does
it signify), or not?

Furthermore, do we suppose that this is the way VS.NET and IIS do it? Like
you, I had imagined there would be a nifty .NET class that would just give
it to me.

Charles


MrPolite said:
well I had another post where I was trying to figure out how to open a
VS.NET solution file, get the project file's path and then open the project
file with a streamReader. It turns out that when the project is an asp.net
project, its path always starts with http://localhost/ and that streamReader
cannot open a path like that. So I'm trying to figure out a way to convert
that path from localhost/whatever to the physical directory's path. I guess
thats the only way I can open the project file...



I've
added
it,
 
umm, not enough coffee yet. Yes, it was a typo. Here is my exported registry
entry:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters\Virtu
al Roots]
"/"="C:\\Inetpub\\wwwroot,,201"

Mike
 
Back
Top