[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 501
  • Last Modified:

Why is VB.NET fileinfo.length giving me different size on Windows Server 2003 vs Windows XP

Hello Experts,

Using VB.NET I am trying to determine the file size before attaching to my e-mail.  Specifically I want to know if a text file is empty.  When testing on Windows XP the function works and returns file size of 0, however, when I deploy to Windows Server 2003 the file size returns 244 B.  All this is tested with the same file, same modification date, etc.

I did not want to open/read the file to see if it contains any data, instead I used the following:

 
Private Function GetFileSize(ByVal strFilePath As String) As Long
        Dim fileObj As FileInfo
        Dim fileSizeBytes As Long = 0

        Try
            If File.Exists(Trim(strFilePath)) Then
                fileObj = New IO.FileInfo(strFilePath)
                fileSizeBytes = fileObj.Length
            End If
        Catch ex As Exception
            ErrorHandler(ex, "GetFileSize")
        End Try

        Return fileSizeBytes
    End Function

Open in new window

test.txt
0
cyman73
Asked:
cyman73
2 Solutions
 
edemcsCommented:
Check to see if the file is save in Unicode in one and not the other.
0
 
OrcbighterCommented:
1. Do both the XP machine and the Server 2003 machine have the same version of .NET installed (.NET 1.1 from your tags)?
2. Have you tried calling the Refresh() method befire getting the size?
0
 
cyman73Author Commented:
Thank you for your suggestions.  I figured out that previous version of my app wasn't uninstalled properly.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now