|
-
List Files in a Directory in VB.NET
- fileArray =
Directory.GetFiles(yourPath)
'you can get
an array of files (their path)
'this example shows how to
loop through a directory and show all of the GIF images
in it.
Dim
pics as ArrayList = new ArrayList()
'an ArrayList to Bind to a
control
Dim myFile as String, code
as String
'file and html code strings
Const
YOUR_DIRECTORY as
String =
"/images/"
'constant for your image
directory
'add the image to your
ArrayList
- For Each myFile
in Directory.GetFiles(Server.MapPath(YOUR_DIRECTORY),
"*.gif")
image = YOUR_DIRECTORY & Path.GetFileName(myFile)
code = "<img src=""" & image & """><br>"
pics.Add(code)
Next
- 'Bind the pics to a
DataList
dlImages.DataSource = pics
dlImages.DataBind
-
List all files in a folder with VB.NET
In .NET you
can use the DirectoryInfo class
of the System.IO namespace to
get a list of files in a particular folder. DirectoryInfo
has a GetFiles method that
returns a file list, as FileInfo
structures, from the specified directory. Optionally,
GetFiles takes a pattern as a parameter that can limit the
list of files returned.
- Imports System.IO
Dim strFileSize As String = ""
Dim di As New IO.DirectoryInfo("C:\temp")
Dim aryFi As IO.FileInfo() = di.GetFiles("*.txt")
Dim fi As IO.FileInfo
- For Each fi In aryFi
strFileSize = (Math.Round(fi.Length /
1024)).ToString()
Console.WriteLine("File Name: {0}",
fi.Name)
Console.WriteLine("File Full Name:
{0}", fi.FullName)
Console.WriteLine("File Size (KB):
{0}", strFileSize )
Console.WriteLine("File Extension:
{0}", fi.Extension)
Console.WriteLine("Last Accessed:
{0}", fi.LastAccessTime)
Console.WriteLine("Read Only: {0}",
(fi.Attributes.ReadOnly = True).ToString)
Next
-
Verifying if a File
Exists...Creating an Intro File if it Does Not Exist
- strDwgPrefix = ThisDrawing.GetVariable("DWGPREFIX")
strDwgName = ThisDrawing.GetVariable("DWGNAME")
strTempPreFix = ThisDrawing.GetVariable("TEMPPREFIX")
x = Dir(strTempPreFix & "PellaVisionDocNoData.dat")
If x <> "" Then
FileExists = True
Open strTempPreFix & "PellaVisionDocNoData.dat" For
Input As #1
Input #1, strDocNoLong
Close #1
ReadPellaVisionDataFile
Else:
FileExists = False
Open strTempPreFix & "PellaVisionDocNoData.dat" For
Output As #1
Write #1, "No DocNo Exists"
Close #1
Open strTempPreFix & "PellaVisionData.dat" For Output As
#1
For x2 = 1 To 200
Write #1, "Line #" & x2 & ", no PellaVisionData.dat
file"
Next x2
Close #1
End If
- VBA - verifying a Listbox
Entity is Highlighted, and then setting a program variable
equal to the highlighted value 01NOV2008
- For i = 0 To lbModel.ListCount - 1
If lbModel.Selected(i) = True Then strModel = lbModel.List(i) Next i
- VB.NET - verifying a Listbox
Entity is Highlighted, and then setting a program variable
equal to the highlighted value 06JAN2009
...and about a zillion more.
Email me if you
have an immediate need.
|