G
Guest
Hoping someone can help with a simple but puzzling problem. I have some code
that I want to build as a class method. The code works fine when I embed it
in Page_Load. But when I try to generalize the code into the method of a
class I am trying to build, it gives me strange errors: "CS0103: The name
'Server' does not exist in the current context". (Server being a call to
Server.MapPath.)
I'm working in ASP.NET 2.0 and VS.NET 2005.
Here's the code that works just fine:
public partial class aspmht_test1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
aspNetMHT.MHT m = new aspNetMHT.MHT();
string protectedUrl = "http://www.google.com";
m.LoadUrl(protectedUrl);
...
string filename = "new" + DateTime.Now.ToFileTime().ToString() + ".zip";
//save it the filesystem.
m.SaveToFile(Server.MapPath(filename), true); // This is where I get
errors if I move to a class method
}
}
So far, so good. When I try to build a 'Scraper' class, and embed the code
in a method, I get errors on the line notated above. Here's my class code:
public class Scraper
{
public void GetPageAndSave(string remoteurl, string savefilename)
{
aspNetMHT.MHT m = new aspNetMHT.MHT();
m.LoadUrl(remoteurl);
m.Parse();
string filename = savefilename +
DateTime.Now.ToFileTime().ToString() + ".zip";
m.SaveToFile(Server.MapPath(filename), true);
}
The code fails on the last line with the error: CS0103: The name 'Server'
does not exist in the current context.
The code above is in Scraper.cs. Here's how I'm calling this in my page
public partial class aspmht_test2 : System.Web.UI.Page
{
public void Page_Load(object sender, EventArgs e)
{
Scraper myScraper = new Scraper();
string myURL = "http://whatever.com";
myScraper.GetPageAndSave(myURL, "whatever");
}
}
Any help out there? I'm outta ideas....Thanks in advance.
-KF
that I want to build as a class method. The code works fine when I embed it
in Page_Load. But when I try to generalize the code into the method of a
class I am trying to build, it gives me strange errors: "CS0103: The name
'Server' does not exist in the current context". (Server being a call to
Server.MapPath.)
I'm working in ASP.NET 2.0 and VS.NET 2005.
Here's the code that works just fine:
public partial class aspmht_test1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
aspNetMHT.MHT m = new aspNetMHT.MHT();
string protectedUrl = "http://www.google.com";
m.LoadUrl(protectedUrl);
...
string filename = "new" + DateTime.Now.ToFileTime().ToString() + ".zip";
//save it the filesystem.
m.SaveToFile(Server.MapPath(filename), true); // This is where I get
errors if I move to a class method
}
}
So far, so good. When I try to build a 'Scraper' class, and embed the code
in a method, I get errors on the line notated above. Here's my class code:
public class Scraper
{
public void GetPageAndSave(string remoteurl, string savefilename)
{
aspNetMHT.MHT m = new aspNetMHT.MHT();
m.LoadUrl(remoteurl);
m.Parse();
string filename = savefilename +
DateTime.Now.ToFileTime().ToString() + ".zip";
m.SaveToFile(Server.MapPath(filename), true);
}
The code fails on the last line with the error: CS0103: The name 'Server'
does not exist in the current context.
The code above is in Scraper.cs. Here's how I'm calling this in my page
public partial class aspmht_test2 : System.Web.UI.Page
{
public void Page_Load(object sender, EventArgs e)
{
Scraper myScraper = new Scraper();
string myURL = "http://whatever.com";
myScraper.GetPageAndSave(myURL, "whatever");
}
}
Any help out there? I'm outta ideas....Thanks in advance.
-KF