0

So, I'm working on converting this code from VB.NET to C#:

FileOpen(1, Application.StartupPath & "\Stub.exe", _
    OpenMode.Binary, OpenAccess.Read, OpenShare.Default)

I've used a series of online converters, and they don't really work for me.

How do I do it? I'm trying to understand VB.NET source code so I can use it in.

1
  • what is this code suppose to do. i.e run Stub.exe application or open a file stream from the Stub.exe file Commented Jun 26, 2011 at 5:52

3 Answers 3

2

Use the following code.

BinaryReader br =
    new BinaryReader(
        new FileStream(Application.StartupPath + "/stub.exe",
        FileMode.Open,
        FileAccess.Read,
        FileShare.Read));
Sign up to request clarification or add additional context in comments.

1 Comment

Note BinaryReader implements IDisposable and should be wrapped in a using statement.
0

The best solution is to redevelop the code using a BinaryReader.

If there's a lot of code and you are pressed for time, you could import Microsoft.VisualBasic into your C# project and then use Microsoft.VisualBasic.FileOpen.

Comments

0

Look at the documentation. There are C# examples provided.

1 Comment

That's System.IO.File.Open, not Microsoft.VisualBasic.FileOpen which is provided for backward compatibility with VB6 code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.