Advertisement

07.21.2008 at 02:06PM PDT, ID: 23583418
[x]
Attachment Details

Question on StreamWriters/Readers in vb.net.

Asked by wally_davis in Microsoft Visual Basic.Net

Tags: vb.net, ie 7.0

My intent is this. I'm going to need to write multiple values during a long routine to one file.
I have a constant and a variable streamwriter that writes to the const file. I want to make sure this file remains open until the very end of the routine. I'm assuming I can use WriteLine and Flush and then use Close at the end.
However, I first need to make sure a folder path exists but can't get through my list of variables listed before my Global variables, Main Sub because when I hit the second line of code below, it throws this error: The type initializer for 'PVT_Maintenance.Module1' threw an exception.
My thought process was that where if I declare my variable globally, it would continue to work for my remaining code. This error is happening because the Folder structure doesn't exist. How can I declare global variables but check that the folder structure where the file will be stored, exists?
Thank you Expert(s),
WallaceStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
Const SQL_Status As String = "C:\Temp\PVT Maintenance\SQL Statuses\1 - SQL Status.log"
Dim swSQLStatus As StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(SQL_Status, True)
--- CAN'T RUN THIS ROUTINE OUTSIDE OF METHOD BODY PRIOR TO CONSTANT VARIABLE---
Sub FldrExist()
        If Directory.Exists("C:\Temp\PVT Maintenance\SQL Statuses") = False Then
            Directory.CreateDirectory("C:\Temp\PVT Maintenance\SQL Statuses")
        End If
    End Sub
 
Loading Advertisement...
 
[+][-]07.22.2008 at 05:27AM PDT, ID: 22058545

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Visual Basic.Net
Tags: vb.net, ie 7.0
Sign Up Now!
Solution Provided By: planocz
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628