Solved

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

Posted on 2013-06-14
4
409 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 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