Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Textbox for extension
Message
General information
Forum:
ASP.NET
Category:
Forms
Environment versions
OS:
Windows XP
Miscellaneous
Thread ID:
01299332
Message ID:
01299358
Views:
17
>>Hi everybody,
>>
>>I'd like to be able to provide a file extension (s ?) and in my code only save files with these extensions.
>>
>>I'm a bit confused as to what to use for these extensions textbox.
>>
>>Any suggestion?
>>
>>Thanks in advance.
>
>Are you using the SaveFileDialog class?
>If so use the Filter property. Something like this
>
>sfd.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*";
>
No, here is what I currently have:

--------------------------
A texbox for the directory (with a little button ... close to it to pick up directory)

A masked textbox for the date with a button close to it to call MonthCalendarControl (I'm stack with this problem right now)

A textbox for extension

A texbox for output file.
==============================
How can I get the whole code for the form as we do in VFP in Class Browser?

Here's what I have right now:
Imports System.IO
Imports System.Text


Public Class Form1
    Dim TargetFileText As New StringBuilder 'declare it outside any function
    Dim InitialDir As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateFile.Click
        'Dim files() As String
        'Dim fileList As New System.Text.StringBuilder
        'Dim myDate As DateTime = Me.dtpModified.Value
        'Dim fileInfo As IO.FileInfo
        If Me.txtDirectory.Text <> "" Then
            If Me.txtOutput.Text = "" Then
                Dim result As DialogResult = Me.SaveFileDialog1.ShowDialog()

                If (result = DialogResult.OK) Then
                    Me.txtOutput.Text = Me.SaveFileDialog1.FileName
                Else
                    Exit Sub
                End If
            End If
            InitialDir = Me.txtDirectory.Text

            GetFiles(InitialDir, Me.txtModifiedDate.Text, Me.txtExtension.Text.ToUpper())
            'files = IO.Directory.GetFiles(Me.txtDirectory.Text, "*.*")

            'For i As Integer = 0 To files.Length - 1
            '    fileInfo = New IO.FileInfo(files(1))
            '    If fileInfo.LastWriteTime > myDate And fileInfo.Extension.ToUpper() = ".ASPX" Then
            '        fileList.Append(files(i))
            '        fileList.Append(Environment.NewLine)
            '    End If
            'Next

            Dim writer As New IO.StreamWriter(Me.txtOutput.Text)
            writer.Write(TargetFileText.ToString)
            writer.Close()
            MsgBox("The file with all latest changes is created")
        Else
            MsgBox("Please select the directory you want to get list of recent changes first!")
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ' Show the FolderBrowserDialog.
        Dim result As DialogResult = FolderBrowserDialog1.ShowDialog()

        If (result = DialogResult.OK) Then
            Me.txtDirectory.Text = FolderBrowserDialog1.SelectedPath

        End If

    End Sub
    'THIS FUNCTION WILL RECUSRSIVELY FIND FILES IN PARTICULAR FOLDER
    Private Sub GetFiles(ByVal DirName As String, ByVal LastDate As Date, ByVal Ext As String)

        Dim d As DirectoryInfo = New DirectoryInfo(DirName)

        Dim f() As FileInfo = d.GetFiles()

        Dim Counter As Integer
        Counter = 0
        ' TargetFileText.Append(vbCrLf + "-------------------------------------------------" + vbCrLf)
        'TargetFileText.Append("Directory: " & d.FullName & vbCrLf)
        'TargetFileText.Append("Name" & vbTab & vbTab & "Bytes" & vbTab & "Last Modified" & vbCrLf)

        Dim fi As FileInfo

        For Each fi In f
            If (Ext = "" Or fi.Extension.ToUpper = Ext) And fi.LastWriteTime > LastDate Then
                Counter = Counter + 1
                If Counter = 1 Then
                    TargetFileText.Append("Directory: " & d.FullName.Replace(InitialDir, "") & Environment.NewLine + Environment.NewLine)
                End If

                TargetFileText.Append(Counter.ToString & vbTab & fi.Name & Environment.NewLine) ' & vbTab & fi.Length & vbTab & fi.LastWriteTime & vbCrLf)
            End If
        Next

        If Counter > 0 Then
            TargetFileText.Append("----------------------------------------------" + Environment.NewLine)
        End If

        Dim innerFolders As DirectoryInfo

        For Each innerFolders In d.GetDirectories()
            GetFiles(innerFolders.FullName, LastDate, Ext)
        Next
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalendar.Click
        Me.MonthCalendar1.Visible = True

    End Sub

    Private Sub MonthCalendar1_DateSelected(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateSelected
        Me.txtModifiedDate.Mask = ""
        Me.txtModifiedDate.Text = e.Start.ToShortDateString()

        Me.MonthCalendar1.Visible = False
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.MonthCalendar1.MaxDate = Today
        Me.MonthCalendar1.MinDate = DateAdd(DateInterval.Year, -1, Today)
        Me.MonthCalendar1.ShowToday = False
        Me.MonthCalendar1.MaxSelectionCount = 1
    End Sub

    
    Private Sub txtModifiedDate_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtModifiedDate.GotFocus
        If Me.txtModifiedDate.Text = "" Then
            Me.txtModifiedDate.Mask = "00/00/00"
        End If
    End Sub

End Class
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform