Results 1 to 19 of 19

Thread: Filesystem Object Vs .NET methods

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    44

    Filesystem Object Vs .NET methods

    is there any disadvantages using Filesystemobject for file operations? which is better .net framework or filesystemobject

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Filesystem Object Vs .NET methods

    I think this article sums it up nicely
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    Addicted Member
    Join Date
    Oct 2007
    Posts
    133

    Re: Filesystem Object Vs .NET methods

    I recently explored this decision, in the end I'm going with Filesystem object.

    Posters here are what got me to look into the .net way and although it seems more robust i still feel i have more control over what i'm trying to accomplish with my file then i do with the .net method.

    Maybe a future project i'll use the .net way but at the moment i'm sticking with old tried and true way. My familiarity may have allot to do with my decision but at the end of the day i can't help feel that i'm much more in control over my data.

    my 2 cents.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Filesystem Object Vs .NET methods

    Once you learn the .NET ways you will rarely go back.

    There are more benefits to using the .NET objects over the legacy MS.VB objects.

    My 3 cents
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Filesystem Object Vs .NET methods

    Indeed. For example, by learning how to use the Stream/Binary writer, you do not only get the knowledge on how to write to filestreams, but then you can apply the exact same knowledge to write to any stream, a networkstream for example.

    My 4 cents
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

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

    Re: Filesystem Object Vs .NET methods

    Quote Originally Posted by sytto
    I recently explored this decision, in the end I'm going with Filesystem object.

    Posters here are what got me to look into the .net way and although it seems more robust i still feel i have more control over what i'm trying to accomplish with my file then i do with the .net method.

    Maybe a future project i'll use the .net way but at the moment i'm sticking with old tried and true way. My familiarity may have allot to do with my decision but at the end of the day i can't help feel that i'm much more in control over my data.

    my 2 cents.
    You can do anything you want with any file down to the byte using .NET file I/O. There is no advantage to using unmanaged code for I/O.

    The classes in the Stsrem.IO namespace are what you should be looking at first. There is also the My.Computer.FileSystem object. Many of the methods of the My.Computer.FileSystem object wrap members of classes in the System.IO namespace. For instance, My.Computer.FileSystem.FileExists calls IO.File.Exists and My.Computer.FileSystem.RenameFile calls IO.File.Move. Many others use the Windows Shell, allowing you to display the same progress dialogues used by Windows Explorer.
    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

  7. #7
    Addicted Member
    Join Date
    Oct 2007
    Posts
    133

    Re: Filesystem Object Vs .NET methods

    Where i ran into uncertainty was when i wanted to get something from my structure at say record 35.

    Obviously I've left some code out,

    fileopen...
    FileGet(freef, mystruct, 35)
    myvar = data.item
    fileclose(freef)

    Super simple, no fuss, no muss, straight to exactly what i want.
    How do you do this the .net way?

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

    Re: Filesystem Object Vs .NET methods

    I've never used FileGet so I don't know exactly what that code does. That said, the documentation for the FileGet function states:
    Quote Originally Posted by MSDN
    The My feature gives you greater productivity and performance in file I/O operations than FileGet. For more information, see My.Computer.FileSystem Object.
    and provides a link. When you follow that link you get a list of tasks you might want to perform and a How To link for each one. Further, you also have the System.IO namespace with classes like BinaryReader etc.
    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

  9. #9
    Addicted Member
    Join Date
    Oct 2007
    Posts
    133

    Re: Filesystem Object Vs .NET methods

    That code basically does this:

    *open file*
    fileopen...

    *get record 35*
    FileGet(freef, mystruct, 35)

    *get the item of data i want from record 35 and put it into a variable*
    myvar = data.item

    *close the file*
    fileclose(freef)

    How you do that the .net way has eluded me.

  10. #10
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Filesystem Object Vs .NET methods

    What do you actually mean by 'record 35'? Sounds like some database stuff
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  11. #11
    Addicted Member
    Join Date
    Oct 2007
    Posts
    133

    Re: Filesystem Object Vs .NET methods

    No database stuff. I create a structure and enter data into it. Then if a persons Record# is 45 i can go straight to record 45 and get their name for example using the code above.

    I dug up a MS example below.

    Code:
    Structure Person 
       Public ID As Integer
       Public Name As String
    End Structure
    
    Sub WriteData()
       Dim PatientRecord As Person
       Dim recordNumber As Integer    
    '    Open file for random access.
       FileOpen(1, "C:\TESTFILE.txt", OpenMode.Binary)
       ' Loop 5 times.
       For recordNumber = 1 To 5 
          ' Define ID.
          PatientRecord.ID = recordNumber   
          ' Create a string.
          PatientRecord.Name = "Name " & recordNumber
          ' Write record to file.
          FilePut(1, PatientRecord)
       Next recordNumber
       FileClose(1)
    End Sub

  12. #12
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Filesystem Object Vs .NET methods

    Sounds like a better way to do all that is serializing/deserializing the structures using XML or binary serialization.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  13. #13
    Addicted Member
    Join Date
    Oct 2007
    Posts
    133

    Re: Filesystem Object Vs .NET methods

    How do code to go straight to a record# and get something from the structure?

  14. #14
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Filesystem Object Vs .NET methods

    to be honest, I have no idea how to do that, as I've never needed to. Being that file operations are relatively slow, I personally dont think you would gain anything if you where able to read and deserialize a only a specific part of the file, it would be better to deserialize the entire file into a collection of the structure at startup, then perform all actions on the collection, and deserialize upon closing the application.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  15. #15
    Addicted Member
    Join Date
    Oct 2007
    Posts
    133

    Re: Filesystem Object Vs .NET methods

    I think I'm seeing why MS actually never pulled the old style, it seems it's better in certain situations.

    Here is a scenario, i have person come to me and and say i'm station 45 and ask what was my time and amount for item whatever.

    The couple simple lines of code i use along with variables gives me the answer as it instantly goes to record 45, gets time and amount.

    If someone could tell me how to do what i do with Filesystemobject in .net i would gladly explore the .net option further.

    I respect your opinions on what you think about Filesystem Object Vs .NET methods but they are kinda biased as it seems there is no previous experience with both methods and are solely answering a question based on what MS has told you.

    So far I'm just not sold on the .net way for this, I'm completely sold on allot of other new .net ways but this, please someone help me see the light. lol Just give me a solid example.

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

    Re: Filesystem Object Vs .NET methods

    Quote Originally Posted by sytto
    I think I'm seeing why MS actually never pulled the old style, it seems it's better in certain situations.

    Here is a scenario, i have person come to me and and say i'm station 45 and ask what was my time and amount for item whatever.

    The couple simple lines of code i use along with variables gives me the answer as it instantly goes to record 45, gets time and amount.

    If someone could tell me how to do what i do with Filesystemobject in .net i would gladly explore the .net option further.

    I respect your opinions on what you think about Filesystem Object Vs .NET methods but they are kinda biased as it seems there is no previous experience with both methods and are solely answering a question based on what MS has told you.

    So far I'm just not sold on the .net way for this, I'm completely sold on allot of other new .net ways but this, please someone help me see the light. lol Just give me a solid example.
    OK, first of all you aren't using a FileSystemObject. A FileSystemObject is a scripting object and you have to add a reference to the Windows Script library in order to access it. You're using standard VB6-style file I/O. The reason it still exists is for backward-compatibility.

    As the MSDN documentation states itself, My.Computer.FileSystem offers better performance than VB6-style I/O. There may well not be a direct equivalent to what you did there, but then there is no need for a direct equivalent. You wouldn't use FilePut to write the data in the first place so you wouldn't use FileGet to read it. In a .NET app you'd use a BinaryWriter/BinaryReader, binary or XML serialisation or a database.
    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

  17. #17
    Addicted Member
    Join Date
    Oct 2007
    Posts
    133

    Re: Filesystem Object Vs .NET methods

    Can you give me an example? That's all I'm looking for, as i said earlier it has eluded me.

  18. #18
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    Re: Filesystem Object Vs .NET methods

    What version of Visual Studio are you using?

  19. #19

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    44

    Re: Filesystem Object Vs .NET methods

    Visual Studio 2005
    Thank you all for replies.
    Thank you Atheist for the MSDN article, that gave me info on fso limitations.

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