Re: Why do I "lose context" when I try to move certain operations to class methods?
- From: <kenfine@xxxxxxxxxxxxxxxx>
- Date: Sun, 24 Jul 2005 01:07:09 -0700
Thanks. In C#, you're saying I need to include an import directive at the
top of the .cs file? What namespace to I need to be importing (which
namespace manages Server.whatever operations?)
Thanks again.
-KF
"Peter Rilling" <peter@xxxxxxxxxxxxxxxxxx> wrote in message
news:uzNq%23SCkFHA.2152@xxxxxxxxxxxxxxxxxxxxxxx
> You have to include the namespace for the Server in the file for your
> helper
> classes. The namespace is defined in the file with your page class, but
> not
> automatically if you create more class files.
>
> <kenfine@xxxxxxxxxxxxxxxx> wrote in message
> news:#s0ojxBkFHA.2852@xxxxxxxxxxxxxxxxxxxxxxx
>>
>> 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
>>
>>
>>
>
>
.
- Follow-Ups:
- Re: Why do I "lose context" when I try to move certain operations to class methods?
- From: Juan T. Llibre
- Re: Why do I "lose context" when I try to move certain operations to class methods?
- References:
- Prev by Date: Re: Why do I "lose context" when I try to move certain operations to class methods?
- Next by Date: HttpContext.Cache
- Previous by thread: Re: Why do I "lose context" when I try to move certain operations to class methods?
- Next by thread: Re: Why do I "lose context" when I try to move certain operations to class methods?
- Index(es):
Relevant Pages
|