• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 511
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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