PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] VB.NET to C# Conversion Issues With Files-VBForums
Results 1 to 4 of 4

Thread: [RESOLVED] VB.NET to C# Conversion Issues With Files

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2016
    Posts
    22

    Resolved [RESOLVED] VB.NET to C# Conversion Issues With Files

    I'm trying to convert a VB.NET project to C#.

    My VB code:
    Code:
            Dim infoReader As System.IO.FileInfo
            infoReader = My.Computer.FileSystem.GetFileInfo(Me.ofdOpenFiles.FileName)
            intRecLength = infoReader.Length
    Is not converting to C# correctly. The conversion process is converting to this code:

    Code:
    System.IO.FileInfo infoReader;
                infoReader = My.MyProject.Computer.FileSystem.GetFileInfo(this.ofdOpenFiles.FileName);
                intRecLength = infoReader.Length;
    Microsoft.VisualBasic is a reference.

    These using statements are also include:

    Code:
    using Microsoft.VisualBasic;
    using System;
    using System.IO;
    Thank you for any assistance. I wouldn't mind getting rid of Microsoft.VisualBasic references and namespaces.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,089

    Re: VB.NET to C# Conversion Issues With Files

    The "My" namespace is basically just a nice grouping of related functionality in the framework, but it tends to create longer code.

    In this case all you need is:
    Code:
            infoReader = new System.IO.FileInfo(Me.ofdOpenFiles.FileName);
    ...or, because you have using System.IO; you can condense it to:
    Code:
            infoReader = new FileInfo(Me.ofdOpenFiles.FileName);

  3. #3
    Member
    Join Date
    Jun 2019
    Posts
    34

    Re: VB.NET to C# Conversion Issues With Files

    C# Code:
    1. using System.IO;
    2. ...
    3. ...
    4.  
    5. var fi = new FileInfo(openFileDialog1.FileName);
    6. var len = fi.Length;

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jul 2016
    Posts
    22

    Re: VB.NET to C# Conversion Issues With Files

    Thanks so much peterst and si_the_geek!

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width