Imports System.IO
Partial Class StrDirectoryList
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim x As Integer = 0
While x = 0
If Directory.Exists("c:\Temp") Then
Dim strDirectoryName As String = "c:\Temp"
'retrieve the list of files, and display it in the page
Dim fileList As String() = Directory.GetFiles(strDirectoryName)
For Each File As String In fileList
lstFiles.Items.Add(File)
Next
x = 1
Else
Response.Write("Directory C:\Temp does not exist")
Response.Write("
Creating directory...")
Dim myDirectory As New DirectoryInfo("c:\Temp")
Dim myFile As New FileInfo("c:\Temp\readme.txt")
'now create them order here is important
myDirectory.Create()
Dim stream As FileStream = myFile.Create()
stream.Close()
End If
End While
End Sub
End Class
Imports System.IO
Imports System.Diagnostics
Partial Class FileBrowser
Inherits System.Web.UI.Page
Private Sub ShowDirectoryContents(ByVal strPath As String)
'define the current directory
Dim dir As New DirectoryInfo(strPath)
'get the DirectoryInfo and fileInfo objects
Dim files As FileInfo() = dir.GetFiles()
Dim dirs As DirectoryInfo() = dir.GetDirectories()
'show the directory listing
lblCurrentDir.Text = "Currently showing " & strPath
gridFileList.DataSource = files
gridDirList.DataSource = dirs
Page.DataBind()
'clear any selection
gridFileList.SelectedIndex = -1
'keep track of the current path
ViewState("CurrentPath") = strPath
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If (Not Page.IsPostBack) Then
ShowDirectoryContents(Server.MapPath("."))
End If
End Sub
Protected Sub cmdUp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdUp.Click
Dim strPath As String = CStr(ViewState("CurrentPath"))
strPath = Path.Combine(strPath, "..")
strPath = Path.GetFullPath(strPath)
ShowDirectoryContents(strPath)
End Sub
Protected Sub gridDirList_SelectedIndexChanged(ByVal source As Object, ByVal e As EventArgs)
'get the selected directory
Dim dir As String = CStr(gridDirList.DataKeys(gridDirList.SelectedIndex).Value)
'now refresh the directory list to
'show the selected directory
ShowDirectoryContents(dir)
End Sub
Protected Sub gridFileList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
'get the selected file
Dim file As String = CStr(gridFileList.DataKeys(gridFileList.SelectedIndex).Value)
'the FormView shows a collection (or list) of items
'to accommodate this model you must add the file object
'to a collection of some sort
Dim files As ArrayList = New ArrayList()
files.Add(New FileInfo(file))
'now show the selected file
formFileDetails.DataSource = files
formFileDetails.DataBind()
End Sub
Protected Function GetVersionInfoString(ByVal strPath As Object) As String
Dim info As FileVersionInfo = FileVersionInfo.GetVersionInfo(CStr(strPath))
Return info.FileName & " " & info.FileVersion & "
" & info.ProductName & " " & info.ProductVersion
End Function
End Class
public partial class SimpleADONetGridView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//create the connection string and command string
string connectionString = @"Data Source=Alfred-PC\SQLExpress" + "Initial Catalog=AdventureWorks; Integrated Security=SSPI";
string commandString = "SELECT [ContactID], [FirstName], [LastName], [EmailAddress] FROM Person.Contact";
//pass the strings to the SqlDataAdapter constructor
SqlDataAdapter dataAdapter = new SqlDataAdapter(commandString, connectionString);
//create a dataset
DataSet dataSet = new DataSet();
//fill the dataset object
dataAdapter.Fill(dataSet, "Customers");
//get the table from the dataset
DataTable dataTable = dataSet.Tables["Customers"];
//bind to the gridview
GridView1.DataSource = dataTable;
GridView1.DataBind();
}
}
Module Module1
Sub Main()
SystemArrayFunctionality()
End Sub
Sub SystemArrayFunctionality()
Console.WriteLine("=> Working with System.Array.")
'initialize items at startup
Dim gothicBands() As String = {"Tones on Tail", "Bauhaus", "Sisters of Mercy"}
'print out names in declared order
Console.WriteLine(" -> Here is the array:")
For i As Integer = 0 To gothicBands.GetUpperBound(0)
'print a name
Console.WriteLine(gothicBands(i) & " ")
Next
Console.WriteLine()
Console.WriteLine()
'reverse them
Array.Reverse(gothicBands)
Console.WriteLine(" -> The reversed array")
'and print them
For i As Integer = 0 To gothicBands.GetUpperBound(0)
'print a name
Console.WriteLine(gothicBands(i) & " ")
Next
Console.WriteLine()
Console.WriteLine()
'clear out all but the final member
Console.WriteLine(" -> Cleared out all but one...")
Array.Clear(gothicBands, 1, 2)
For i As Integer = 0 To gothicBands.GetUpperBound(0)
'print a name
Console.WriteLine(gothicBands(i) & " ")
Next
Console.WriteLine()
End Sub
End Module
Module Module1
Enum EmpType As Byte
Manager = 10
Grunt = 1
Contractor = 100
VicePresident = 9
End Enum
Sub Main()
Console.WriteLine("***** Fun with Enums *****")
'make a contractor type
Dim emp As EmpType = EmpType.Contractor
AskForBonus(emp)
Dim emp2 As EmpType = EmpType.Manager
AskForBonus(emp2)
End Sub
Sub AskForBonus(ByVal e As EmpType)
Select Case (e)
Case EmpType.Contractor
Console.WriteLine("You already get enough cash...")
Case EmpType.Grunt
Console.WriteLine("You have got to be kidding...")
Case EmpType.Manager
Console.WriteLine("How about stock options instead?")
Case EmpType.VicePresident
Console.WriteLine("VERY GOOD, Sir!")
End Select
End Sub
End Module
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment