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

Posted on 2011-05-05
Last Modified: 2012-05-11
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

            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

Question by:cyman73
    LVL 8

    Accepted Solution

    Check to see if the file is save in Unicode in one and not the other.
    LVL 9

    Assisted Solution

    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?

    Author Closing Comment

    Thank you for your suggestions.  I figured out that previous version of my app wasn't uninstalled properly.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now