Wrox Programmer Forums
|
Visual Basic 2008 Essentials If you are new to Visual Basic programming with version 2008, this is the place to start your questions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2008 Essentials section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 25th, 2008, 05:07 AM
Registered User
 
Join Date: Aug 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to cheh
Default StreamWriter problem

Hi! I'm new to the VB.NET programming, well programming in general actually. I hope I am posting this in the right section.

I'm writing an application that pops up an OpenFile dialog, then writes the path of the selected file in a .txt file, so that an outside application can read it.

Here is the code that is supposed to do that:

Private Sub btnIzberi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIzberi.Click

        Dim strFileName As String
        With OpenFileDialog1
            .Filter = "Text files (*.txt)|*.txt"
            .FilterIndex = 1
            .InitialDirectory = "C:\"
            .Title = "Choose a text file"
        End With

        If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            strFileName = OpenFileDialog1.FileName
            Dim pisalnik As New StreamWriter(MyFile)
            pisalnik.WriteLine(strFileName)
            pisalnik.Close()
        Else
            Exit Sub
        End If

        txtAnalizaCrkInParov.Text = "You selected the file: " & strFileName

    End Sub


There is also a button that launches the external application that is supposed to read the file.
My problem is that the application CANNOT read the file I created (MyFile), therefore can't do it's job right.

Why won't StreamWriter let go of the file, so that an external application can use it? My best guess is that it has something to do with the OpenFileDialog, but I have no idea what, or how to fix it.

Please help me, I'm dying over here! :\


Greetz, cheh

Slovenian Hardstyle Community
 
Old August 26th, 2008, 03:18 AM
Registered User
 
Join Date: Aug 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to cheh
Default

OK, never mind, I've solved the problem. You change the working directory with open file dialog. Helps if you use a special folder instead of an absolute path (ex. .InitialDirectory = Environment.SpecialFolder.MyDocuments).

Also you have to set the working directory to the outsite process you are launching. :)

http://www.hardstyle.si/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Needed: StreamWriter Function OnceANewbie Visual Basic 2005 Basics 1 August 10th, 2009 05:50 AM
FileStream vs StreamWriter Makolyte C# 2005 0 June 22nd, 2007 01:22 PM
How To Use StreamWriter Slago VS.NET 2002/2003 7 April 4th, 2006 03:32 PM
What object is streamwriter located under? kenn_rosie ASP.NET 1.0 and 1.1 Basics 0 February 21st, 2006 08:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.