Problem with string function in code-behind

mickey01

New Member
I have the following function:<BR><BR>Function BaseName(File as string)<BR> dim strBaseName as string <BR> strBaseName = Mid(File,1,InstrRev(File,".")-1)<BR> return strBaseName<BR>End Function<BR><BR>where file is a filename with an extension.. I am wanting to get the filename without the extension. It works fine in my .aspx page.<BR><BR>The problem I'm having it this: As I try to separate my code into a .vb code-behind form, I'm getting an error:<BR><BR>Compiler Error Message: BC30451: The name 'Mid' is not declared.<BR><BR>I also tried the function as:<BR>Function BaseName(File as string)<BR> dim strBaseName as string <BR> strBaseName = strBaseName.Mid(File,1,InstrRev(File,".")-1)<BR> return strBaseName<BR>End Function<BR><BR>and I get this error: <BR><BR>Compiler Error Message: BC30456: The name 'Mid' is not a member of 'String'.<BR><BR>I am thinking maybe I am not importing something that I need.. right now I am importing:<BR><BR>imports System<BR>Imports System.IO<BR>Imports System.Web<BR>Imports System.Web.UI<BR>Imports System.Web.UI.WebControls<BR>Imports System.Web.UI.HTMLControls<BR>Imports System.Data<BR>Imports System.Data.sqlClient<BR>imports System.DateTime<BR>imports System.Drawing<BR>imports System.Drawing.Imaging<BR>imports System.string<BR><BR>Can anyone help with this please? It's driving me nuts.<BR><BR>Is to use the Path class's GetExtension method. See:<BR>ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemiopathclassgetextensiontopic.htm<BR><BR>You just do:<BR><BR>Dim extension as String<BR>extension = Path.GetExtension(filename)<BR><BR>And you're off and running! The Path class also has other useful methods, like GetFileName, GetFullPath, etc. Check it out.-NT
 
Back
Top