Re: Why do I "lose context" when I try to move certain operations to class methods?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
>>
>>
>>
>
>


.



Relevant Pages

  • Re: Why do I "lose context" when I try to move certain operations to class methods?
    ... You have to include the namespace for the Server in the file for your helper ... > that I want to build as a class method. ... > public void GetPageAndSave ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: empty classes as c structs?
    ... Hmm, so if it doesn't find it in the current namespace, it looks in the parent? ... binding always happens in the innermost scope, so binding a name in a namespace ... from outer scopes, and later regain access to them using 'del'. ... Have a class method which allows a namespace to be 'put inside' another ...
    (comp.lang.python)
  • Re: empty classes as c structs?
    ... > Hmm, so if it doesn't find it in the current namespace, it looks in the parent? ... > binding always happens in the innermost scope, so binding a name in a namespace ... > Have a class method which allows a namespace to be 'put inside' another ... blog: http://rascunhosrotos.blogspot.com ...
    (comp.lang.python)
  • Re: Namaspaces, caling functions and classes defined in the global name space
    ... But prefixing it with GLOBAL doesn't help matters. ... Could be a function foo() in namespace GLOBAL::A or a class method ... A::fooin namespace GLOBAL. ...
    (comp.lang.php)
  • Re: namespace issue
    ... living in the same namespace and the class method using the ... def great_name: ...
    (comp.lang.python)