can we use "Server.MapPath" in non webpage file ?

  • Thread starter Thread starter Tee
  • Start date Start date
T

Tee

Hi,

I am currently using Server.MapPath in my aspx files, but because of I am
using it more than once, I would like to move these code away from aspx and
make it as a public function inside Module, but I am having problem with it.
As "Server.MapPath" is not allow in other .vb file ... can anyone help with
this ? or if we really can't make it, is there any other way could do it ?


Thanks,
Tee
 
Tee said:
Hi,

I am currently using Server.MapPath in my aspx files, but because of I am
using it more than once, I would like to move these code away from aspx and
make it as a public function inside Module, but I am having problem with it.
As "Server.MapPath" is not allow in other .vb file ... can anyone help with
this ? or if we really can't make it, is there any other way could do it ?

Your problem isn't that "Server.MapPath" is not allowed in another .vb file.
Your problem is that "Server" is not defined in that other .vb file.

When you reference "Server" in your .aspx page, you're really referencing
"Page.Server", which is a copy of Page.Context.Server. The latter can also
be referenced in your other .vb file as HttpContext.Current.Server.
 
OK, now I get it, thanks


John Saunders said:
?

Your problem isn't that "Server.MapPath" is not allowed in another .vb file.
Your problem is that "Server" is not defined in that other .vb file.

When you reference "Server" in your .aspx page, you're really referencing
"Page.Server", which is a copy of Page.Context.Server. The latter can also
be referenced in your other .vb file as HttpContext.Current.Server.
 
Back
Top