Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Moving VB's FileSystemObject to C#

Moving VB's FileSystemObject to C#

Scheduled Pinned Locked Moved C#
questioncsharphelp
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I am in the process of moving VB code to C#. However, I have encountered a stumbling block. I have the following code in VB below that uses the Scripting.FileSystemObject and the Scripting.File object. How would I program this property below in C#? Would I use the System.IO.File in place of the Scripting.File object? If so, what would I use for the Scripting.FileSystemObject? Would I open a filestream? If I do, FileSystemObject grabs the whole file, how do I do that using filestreams? VB Code... Private mvarFSO As Scripting.FileSystemObject Private mvarLocalFile As Scripting.File Public Property Get LocalFile() As Scripting.File Set mvarLocalFile = Nothing If mvarFSO.FileExists(mvarMyVSSItem.LocalSpec) Then Set mvarLocalFile = mvarFSO.GetFile(mvarMyVSSItem.LocalSpec) End If Set LocalFile = mvarLocalFile End Property C# Translation... private something_like_FileSystemObject mvarFSO; private something_like_File_object mvarLocalFile; public return_type LocalFile { get { ??? return mvarLocalFile; } } Help please, I'm stumped... Eric

    S M Richard DeemingR J 4 Replies Last reply
    0
    • L Lost User

      I am in the process of moving VB code to C#. However, I have encountered a stumbling block. I have the following code in VB below that uses the Scripting.FileSystemObject and the Scripting.File object. How would I program this property below in C#? Would I use the System.IO.File in place of the Scripting.File object? If so, what would I use for the Scripting.FileSystemObject? Would I open a filestream? If I do, FileSystemObject grabs the whole file, how do I do that using filestreams? VB Code... Private mvarFSO As Scripting.FileSystemObject Private mvarLocalFile As Scripting.File Public Property Get LocalFile() As Scripting.File Set mvarLocalFile = Nothing If mvarFSO.FileExists(mvarMyVSSItem.LocalSpec) Then Set mvarLocalFile = mvarFSO.GetFile(mvarMyVSSItem.LocalSpec) End If Set LocalFile = mvarLocalFile End Property C# Translation... private something_like_FileSystemObject mvarFSO; private something_like_File_object mvarLocalFile; public return_type LocalFile { get { ??? return mvarLocalFile; } } Help please, I'm stumped... Eric

      S Offline
      S Offline
      Steven Lyons
      wrote on last edited by
      #2

      Not sure how much help this will be but... You can still use the Scripting.FileSystemObject in C# if you would like. The code would be pretty close to what you have already, just change it to use the new syntax. Very quick and easy. You can also use the IO libraries provided by .NET but you will, obviously, have to re-do all the code that calls this property. Off the top of my head, I can't really tell you what needs to change but I would probably stick with the Scripting.FileSystemObject if you're porting. It's usually easier to change as little as possible and make sure it's working before moving on. Cheers, steve

      1 Reply Last reply
      0
      • L Lost User

        I am in the process of moving VB code to C#. However, I have encountered a stumbling block. I have the following code in VB below that uses the Scripting.FileSystemObject and the Scripting.File object. How would I program this property below in C#? Would I use the System.IO.File in place of the Scripting.File object? If so, what would I use for the Scripting.FileSystemObject? Would I open a filestream? If I do, FileSystemObject grabs the whole file, how do I do that using filestreams? VB Code... Private mvarFSO As Scripting.FileSystemObject Private mvarLocalFile As Scripting.File Public Property Get LocalFile() As Scripting.File Set mvarLocalFile = Nothing If mvarFSO.FileExists(mvarMyVSSItem.LocalSpec) Then Set mvarLocalFile = mvarFSO.GetFile(mvarMyVSSItem.LocalSpec) End If Set LocalFile = mvarLocalFile End Property C# Translation... private something_like_FileSystemObject mvarFSO; private something_like_File_object mvarLocalFile; public return_type LocalFile { get { ??? return mvarLocalFile; } } Help please, I'm stumped... Eric

        M Offline
        M Offline
        Masaaki Onishi
        wrote on last edited by
        #3

        Hello, the codegurus around the world.;) Just hints.

        try
        {
        string tempS = "You need the right path";
        FileSystemObject fso = new FileSystemObject();
        Scripting.File fInfo = fso.GetFile(tempS);
        }
        catch {fInfo = null;}

        Please, don't send me your email about your questions directly. Have a nice day! Sonork - 100.10571:vcdeveloper ;)

        -Masaaki Onishi-

        1 Reply Last reply
        0
        • L Lost User

          I am in the process of moving VB code to C#. However, I have encountered a stumbling block. I have the following code in VB below that uses the Scripting.FileSystemObject and the Scripting.File object. How would I program this property below in C#? Would I use the System.IO.File in place of the Scripting.File object? If so, what would I use for the Scripting.FileSystemObject? Would I open a filestream? If I do, FileSystemObject grabs the whole file, how do I do that using filestreams? VB Code... Private mvarFSO As Scripting.FileSystemObject Private mvarLocalFile As Scripting.File Public Property Get LocalFile() As Scripting.File Set mvarLocalFile = Nothing If mvarFSO.FileExists(mvarMyVSSItem.LocalSpec) Then Set mvarLocalFile = mvarFSO.GetFile(mvarMyVSSItem.LocalSpec) End If Set LocalFile = mvarLocalFile End Property C# Translation... private something_like_FileSystemObject mvarFSO; private something_like_File_object mvarLocalFile; public return_type LocalFile { get { ??? return mvarLocalFile; } } Help please, I'm stumped... Eric

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          using System.IO;
          ...
          private FileInfo mvarLocalFile;

          public FileInfo LocalFile
          {
          get
          {
          string path = mvarMyVSSItem.LocalSpec;
          if (File.Exists(path))
          mvarLocalFile = new FileInfo(path);
          else
          mvarLocalFile = null;

              return mvarLocalFile;
          }
          

          }

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          1 Reply Last reply
          0
          • L Lost User

            I am in the process of moving VB code to C#. However, I have encountered a stumbling block. I have the following code in VB below that uses the Scripting.FileSystemObject and the Scripting.File object. How would I program this property below in C#? Would I use the System.IO.File in place of the Scripting.File object? If so, what would I use for the Scripting.FileSystemObject? Would I open a filestream? If I do, FileSystemObject grabs the whole file, how do I do that using filestreams? VB Code... Private mvarFSO As Scripting.FileSystemObject Private mvarLocalFile As Scripting.File Public Property Get LocalFile() As Scripting.File Set mvarLocalFile = Nothing If mvarFSO.FileExists(mvarMyVSSItem.LocalSpec) Then Set mvarLocalFile = mvarFSO.GetFile(mvarMyVSSItem.LocalSpec) End If Set LocalFile = mvarLocalFile End Property C# Translation... private something_like_FileSystemObject mvarFSO; private something_like_File_object mvarLocalFile; public return_type LocalFile { get { ??? return mvarLocalFile; } } Help please, I'm stumped... Eric

            J Offline
            J Offline
            joan_fl
            wrote on last edited by
            #5

            I would use the System.IO namespace... To me it's more of a cleaner interface than the plain old FileSystemObject. Though I'm partial to C#. :) System.IO.FileInfo fileinfo = new System.IO.FileInfo(filename); fileinfo.Open(System.IO.FileMode.OpenOrCreate);

            L 1 Reply Last reply
            0
            • J joan_fl

              I would use the System.IO namespace... To me it's more of a cleaner interface than the plain old FileSystemObject. Though I'm partial to C#. :) System.IO.FileInfo fileinfo = new System.IO.FileInfo(filename); fileinfo.Open(System.IO.FileMode.OpenOrCreate);

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Thank you for the help, I got it to work with the code you wrote. Thanks richard_d (on both sites) and joan_fl!!!

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups