Solved

StreamWriter

Posted on 2014-03-12
3
184 Views
Last Modified: 2014-03-12
I am scratching this bit of code together and running into a little unusual behavior.  Irrespective of the path I assign to the file it seems to be placing it in.

C:\Users\symingtonc\Documents\Visual Studio 2008\Projects\PIAuditorware\PIAuditorware\bin\Debug\C\ScannerExport

Can explain why this might be and a remedy, I am not receiving an error message at any point.



  Public Function ExportFile() As Boolean
        Dim TempPath As String = "C\ScannerExport\"
        TempPath = My.Computer.FileSystem.SpecialDirectories.MyDocuments

        If Not Directory.Exists(TempPath) Then
            Directory.CreateDirectory(TempPath)
        End If

        TempPath &= "\export.txt"
        If File.Exists(TempPath) Then File.Delete(TempPath)

        If File.Exists("C\ScannerExport\export.txt") Then File.Delete("C\ScannerExport\export.txt")
        Using WriteTo As StreamWriter = New StreamWriter(File.Open("C\ScannerExport\export.txt", FileMode.CreateNew))
            For Each stkItem As XMLStock In StockList
                Dim NewLine As String = String.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}", BranchNumber, Now.ToShortDateString, stkItem.LongCode, stkItem.ShortCode, stkItem.ProductDescription, stkItem.CurrentStockUnits, IIf(stkItem.Specific, "TRUE", "FALSE"), IIf(stkItem.MarkedDown, "TRUE", "FALSE"))
                WriteTo.WriteLine(NewLine)
            Next
        End Using
    End Function

Open in new window

0
Comment
Question by:Alyanto
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
Ess Kay earned 500 total points
ID: 39923970
delete line 3 :


TempPath = My.Computer.FileSystem.SpecialDirectories.MyDocuments



also, if you want C drive and not C folder


you need to add the colon

c:/

not c/
0
 
LVL 1

Author Comment

by:Alyanto
ID: 39924000
I was about to edit that out from the question because it is actually a bit misleading.  The paths are entered in lines 12 and 13.    

I wanted to experiment with the path which is why it is done that way.  Line 3 is where I would really like to place the files.
0
 
LVL 1

Author Closing Comment

by:Alyanto
ID: 39924075
C:\ was the trick.  Maybe I need to take a break.  Many thanks Aly
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net - TypeInitializer Error 25 32
SQL LINE CONTINUATION ISSUE 12 38
Import a txt file into a DataGridView and TextBox 20 52
No Data for DropDown List 2 29
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

821 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