Solved

VB.Net Why doesnt this code work from the command line

Posted on 2013-06-14
4
404 Views
Last Modified: 2013-06-14
Hi Experts.   I'm testing some code in both a forms application and console application.  The code is this in the console or the same placed in the form load in the forms application.
 
Sub Main()
        Try
            My.Computer.FileSystem.WriteAllText("Test.txt", "Text,", True)
            MsgBox("")
            My.Computer.FileSystem.WriteAllText("Test2.txt", "Text,", True)
            End
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

If I go to the Release folder and double click either program it works correctly and the files are created in the Release Folder.

If I run either program from the command line, the messagebox appears but the files are not created.  

Please can someone explain why?

Thanks for the help.
0
Comment
Question by:PNRT
  • 2
4 Comments
 
LVL 11

Expert Comment

by:Paul S
ID: 39248774
try using an alternate name space for the same actions.

File Class (System.IO)
http://msdn.microsoft.com/en-us/library/system.io.file.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

it could be a problem with the my.computer name space.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39248965
Where are you running the console application from? You haven't specified an absolute path, so the file "Test.txt" is being written to the working directory of the console window.
0
 
LVL 2

Author Comment

by:PNRT
ID: 39248968
No luck Im afraid, tried different types including just creating the file.  All work when you doubleclick the file but nothing works when run from the command line
0
 
LVL 2

Author Comment

by:PNRT
ID: 39248978
Absolutley right Kaufmed, was there when I specified the path
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question