Results 1 to 7 of 7

Thread: Pre-cache FileInfo.Length for transfer of info

  1. #1

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    Pre-cache FileInfo.Length for transfer of info

    I have built a program which serializes and transmits FileInfos across a network.

    It worked good until I tried getting the FileInfo.Length on the computer which has received a FileInfo that is about a file on another computer. It fails saying the file doesn't exist since the Length isn't stored in the FileInfo when declaring it.

    To simplify it:

    Is it possible to pre-store the Length of the file before sending the FileInfo to another computer where the file doesn't exist?

    Or will I need to write my own FileInfoX Class which kinda just copies a FileInfo, and then stores all the variables?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Pre-cache FileInfo.Length for transfer of info

    The FileInfo class has an internal structure that stores the file information. If you get a property such as Length then it will presumably populate that structure. Assuming binary serialisation, that data should then make the trip. I'd say just try it for yourself and see.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    Re: Pre-cache FileInfo.Length for transfer of info

    I don't know if I understand what you mean completely, but I added a line before the serialization (yes binary) like this:

    Code:
    long size = info.Length;
    Though even if I remove that line the FileInfo.Length property contains a value if I put a breakpoint before the serialization.

    But somehow, that value is either lost when deserializing or the new fileinfo just wants to refresh :/

  4. #4
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Pre-cache FileInfo.Length for transfer of info

    can you post the entire code? And could you also explain what it is you are trying to achieve here?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  5. #5

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    Re: Pre-cache FileInfo.Length for transfer of info

    I am trying to send the FileInfo, with the code in my other thread you answered to recently, to another computer (first I serialize it). I am making a remote file browser to learn more about networking in C#

    So yeah, the code basically works like this:

    Create a list of FileInfo which we populate with a loop with all the files in a specific dir.
    Then we binary serialize that list.
    Then we transfer the bytes (converted to a string) to the other computer.

    That computer deserializes it. When I look in the fileInfos in that list, there is no length info. It just says the error "Can't find file" or something like that, which is logical.

    So I have at least one option: I create my own FileInfo class who uses FileInfo on the first computer to get all the info, but then it statically stores the info, instead of dynamically retrieving properties such as the Length.

  6. #6
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Pre-cache FileInfo.Length for transfer of info

    it probably is the best thing to do - to create your own implementation of FileInfo but holds just informational values which you then serialize/deserialize.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  7. #7

    Thread Starter
    Hyperactive Member Cyb3rH4Xter's Avatar
    Join Date
    May 2009
    Location
    Sweden
    Posts
    449

    Re: Pre-cache FileInfo.Length for transfer of info

    I see, well to work then. Thx for the answer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width