tags:

views:

224

answers:

3

Hi,

In Form1 i have a Textbox1, in this textbox i have the loaction of a file "C:\folder\file.iso"

In the Form2 i want to get the file size of the file in Textbox1 so i tried this

        Dim fileDetail As IO.FileInfo


    fileDetail = My.Computer.FileSystem.GetFileInfo(Form1.Textbox1.Text)

    Label1.Text = Size: fileDetail.Length
End Sub

I dont get an error, but the size of the file isn't showed in the label.

Edit: This doesnt seem to work

Private Sub Unscramble_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    If System.IO.File.Exists(Form1.TextBox2.Text) Then
        Dim fi As New System.IO.FileInfo(Form1.TextBox2.Text)
        Label3.Text = "Size: " & fi.Length.ToString()
    End If
End Sub

It still doesnt give me the size of the file nor it gives the "Size:"

+2  A: 
' this is the first(main) form'
Public Class Form1

  Private Sub Button1_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles Button1.Click

    ' create the form2 by PASSING it the file path in constructor'
    Dim f2 As New Form2(TextBox1.Text)
    f2.ShowDialog()
  End Sub
End Class

' this is the second form'
Public Class Form2
  Inherits Form
  Private _filePath As String
  Private Label1 As Label

  Public Sub New(ByVal filePath As String)
    _filePath = filePath
  End Sub

  ' this is the _Load method of the second form'
  Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
    MyBase.OnLoad(e)

    If IO.File.Exists(_filePath) Then
      Dim fi As New IO.FileInfo(_filePath)
      Label1.Text = "Size :" & fi.Length.ToString()
    End If
  End Sub
End Class
serhio
Doesn't seem to work :(
PandaNL
what do you mean? what is the `fi.Length` value?
serhio
+1  A: 
    Dim fileDetail = My.Computer.FileSystem.GetFileInfo(form1.Textbox1.Text)
    Label1.Text = "Size : " & fileDetail.Length
plenderj
Tried both methods but it doesnt show me anything
PandaNL
A: 

Code works perfect but something in my project is blocking it.

Created a new project and it worked perfect.

PandaNL