Wrox Programmer Forums
|
BOOK: Professional ASP.NET 1.0, Special Edition/1.1
This is the forum to discuss the Wrox book Professional ASP.NET 1.1 by Alex Homer, Dave Sussman, Rob Howard, Brian Francis, Karli Watson, Richard Anderson; ISBN: 9780764558900
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 1.0, Special Edition/1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 18th, 2004, 05:24 PM
Registered User
 
Join Date: Mar 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default error BC30451: Name 'MapPath' is not declared.

I had a problem compiling a VB business component with the MapPath procedure within. I got a response from a member suggesting that I start a new topic on the subject. If you have ever had issues with using the MapPath procedure or have suggestions, send in a response.

Cheers!

 
Old March 18th, 2004, 06:20 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there again,

You must have misunderstood my previous answer, as I posted the solution to your problem there already, albeit a bit short.

It's not really that the usage of the MapPath method differs depending on where it is used, it's the namespace that hosts the method that is important. The method must be reachable from within the current code.

The MapPath method lives in the HttpServerUtility class, which in turn lives in the System.Web namespace. This means that outside this namespace, or without referencing this namespace, you cannot call this method.

If you think about it a bit, it makes sense. What would MapPath do do for a file in a Windows app? Since you are already working with physical locations, the answer is: probably nothing.

Now, a component is a bit different. A component can be used in multiple other projects: Web applications, Web services, Desktop apps, console apps etc. Your component is "accidentally" used in a Web app. This means that by default it's not "web aware". To become web aware, you need to get a reference to the "current" httpcontext: that is, the context of the application that uses your component (still with me??)

So, if you needed to use other Web stuff, like Response.Write, Request.ServerVariables, here's what you could do:
Code:
' Get the current context
Dim currentContext As System.Web.HttpContext = System.Web.HttpContext.Current

' With this context object, you can do what
' you usually do. A few examples:
Dim test As String = currentContext.Request.QueryString.Get("Test")
' Or use MapPath
Dim myString As String = currentContext.Server.MapPath("Bla.txt")
You are probably not aware of the complexity behind all this, because most of it is shielded from you in day to day operations. For your convenience, the developers of ASP.NET have added Server, Request, Response, etc properties to the Page class for you. Since the Page class (or any derived child) is the "current" class (Me, or this), there is no need to explicitly reference that class. So, Me.Server.MapPath is the same as Server.MapPath when used within a page.


Does this clarify things?


Cheers,

Imar



---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
'attribute is not declared' error jihadbuster XSLT 6 April 2nd, 2008 01:20 PM
BC30451: Name 'My' is not declared abc052107 Visual Studio 2005 0 July 2nd, 2007 11:01 PM
"Name My " not declared error ajkumar Visual Basic 2005 Basics 0 April 19th, 2007 11:29 PM
element is not declared. An error occurred... dazzled XML 3 September 13th, 2004 04:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.