Friday, March 16, 2012

Populating a List Box

Hi

I am trying to populate a list box with all my themes that i have created but I keep getting an message which is

Type DirectoryInfo is not defined i m guessing i have to declare if but i dont know how are where please could you guys help. Thanks

1Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)23If (Not Page.IsPostBack)Then45 Dim themeDirAs New DirectoryInfo(Server.MapPath("App_Themes"))6 lstThemes.DataTextField ="Name"7 lstThemes.DataSource = themeDir.GetDirectories()8 lstThemes.DataBind()910End If1112 End Sub13

The DirectoryInfo class is located under the System.IO namespace.


Yeah i tired declaring it as Inherits System.IO. Is that the correct appraoch


hello i ve tried to use the system io like u suggested but i still have the same problem here s my code. Do u have any ideas where i am going wrong cheers

PartialClass _Default

Inherits System.Web.UI.Page

Inherits System.IO

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)

If (Not Page.IsPostBack)Then

Dim themeDirAsNew DirectoryInfo(Server.MapPath("App_Themes"))

lstThemes.DataTextField ="Name"

lstThemes.DataSource = themeDir.GetDirectories()

lstThemes.DataBind()

EndIf

EndSub

EndClass


Is your App_Thems directory in your web directory? I would check the path returned by Server.MapPath("App_Theme"), perhaps it doesn't exists and that's why you're getting an error.

bigyawn_hippo:

hello i ve tried to use the system io like u suggested but i still have the same problem here s my code. Do u have any ideas where i am going wrong cheers

PartialClass _DefaultInherits System.Web.UI.Page

Inherits System.IO

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)

If (Not Page.IsPostBack)Then

Dim themeDirAsNew DirectoryInfo(Server.MapPath("App_Themes"))

lstThemes.DataTextField ="Name"

lstThemes.DataSource = themeDir.GetDirectories()

lstThemes.DataBind()

EndIf

EndSub

EndClass

Hi,

Based on my understanding, you want to import the System.IO namespace in your asp.net VB application. If I have misunderstood you, please feel free to let me know.

The DirectoryInfo class is in the System.IO. If we want to use it, we can import it. For example:

Imports System.IOPartialClass _DefaultInherits System.Web.UI.PageProtected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)If (Not Page.IsPostBack)Then Dim themeDirAs New DirectoryInfo(Server.MapPath("App_Themes")) lstThemes.DataTextField ="Name" lstThemes.DataSource = themeDir.GetDirectories() lstThemes.DataBind()End If End SubEnd Class

Alternatively, we can use this namespace in the code behind directly, for example:

Dim themeDir As NewSystem.IO.DirectoryInfo(Server.MapPath("App_Themes"))

Besides, you can find more information about asp.net by the following link:http://www.asp.net/get-started/.


I hope this helps.


Hi hyppo,

why don't you try to put only this two instructions ?

lstThemes.DataSource = themeDir.GetDirectories()
lstThemes.DataBind()

I found my code doing the same and i didn' t write ...DataTextField

0 comments:

Post a Comment