From: mp on 10 Jun 2010 21:16 according to online elearning (ms) to write to a debug log use the following: 'd. FileInfo fi = new FileInfo(@"c:\application.log"); ' StreamWriter sw = fi.AppendText(); I can't seem to convert that to vb successfully Dim fi As FileInfo = New FileInfo(m_DebugFileName) 'this didn't work Dim sw As StreamWriter = New StreamWriter(fi.AppendText()) 'so i tried this and still no joy Dim sw As StreamWriter = New StreamWriter(fi) Error 1 Overload resolution failed because no accessible 'New' can be called with these arguments: 'Public Sub New(path As String)': Value of type 'System.IO.FileInfo' cannot be converted to 'String'. 'Public Sub New(stream As System.IO.Stream)': Value of type 'System.IO.FileInfo' cannot be converted to 'System.IO.Stream'. plus i see no where to pass the text i want to write to the file any help? thanks mark
From: Armin Zingler on 10 Jun 2010 22:15 Am 11.06.2010 03:16, schrieb mp: > according to online elearning (ms) > to write to a debug log use the following: > 'd. FileInfo fi = new FileInfo(@"c:\application.log"); > > ' StreamWriter sw = fi.AppendText(); > > I can't seem to convert that to vb successfully > > Dim fi As FileInfo = New FileInfo(m_DebugFileName) Did you import System.IO ? > 'this didn't work > > Dim sw As StreamWriter = New StreamWriter(fi.AppendText()) Dim sw As StreamWriter = fi.AppendText() The AppendText function already creates a FileStream and returns a StreamWriter writing into the stream. It's the same as Dim sw As New StreamWriter(fi.FullName, True) (I don't know why it's called "AppendText". You could append everything.) > 'so i tried this and still no joy > > Dim sw As StreamWriter = New StreamWriter(fi) Dim sw As StreamWriter = New StreamWriter(fi.fullname) > Error 1 Overload resolution failed because no accessible 'New' can be called > with these arguments: > 'Public Sub New(path As String)': Value of type 'System.IO.FileInfo' > cannot be converted to 'String'. > 'Public Sub New(stream As System.IO.Stream)': Value of type > 'System.IO.FileInfo' cannot be converted to 'System.IO.Stream'. > plus i see no where to pass the text i want to write to the file > > any help? I don't see it, too. ;-) sw.writeline("yadda") There are several ways to write to a file. For example: Using fs = fi.Open(FileMode.Append, FileAccess.Write, FileShare.Read) Using sw As New StreamWriter(fs, System.Text.Encoding.Default) sw.WriteLine("abc") End Using End Using Or, if you just want to open, write, close a/to a file: File.AppendAllText(Path, "abc", System.Text.Encoding.Default) -- Armin
From: mp on 10 Jun 2010 22:44 "Armin Zingler" <az.nospam(a)freenet.de> wrote in message news:OLzJ2wQCLHA.3880(a)TK2MSFTNGP04.phx.gbl... > Am 11.06.2010 03:16, schrieb mp: >> according to online elearning (ms) >> to write to a debug log use the following: >> 'd. FileInfo fi = new FileInfo(@"c:\application.log"); >> >> ' StreamWriter sw = fi.AppendText(); >> >> I can't seem to convert that to vb successfully >> >> Dim fi As FileInfo = New FileInfo(m_DebugFileName) > > Did you > import System.IO > ? yes, otherwise the error would have been missing reference or something? > > >> 'this didn't work >> >> Dim sw As StreamWriter = New StreamWriter(fi.AppendText()) > > > Dim sw As StreamWriter = fi.AppendText() > > The AppendText function already creates a FileStream and returns > a StreamWriter writing into the stream. It's the same as > > Dim sw As New StreamWriter(fi.FullName, True) > > > (I don't know why it's called "AppendText". You could append everything.) > >> 'so i tried this and still no joy >> >> Dim sw As StreamWriter = New StreamWriter(fi) > > Dim sw As StreamWriter = New StreamWriter(fi.fullname) > >> Error 1 Overload resolution failed because no accessible 'New' can be >> called >> with these arguments: >> 'Public Sub New(path As String)': Value of type 'System.IO.FileInfo' >> cannot be converted to 'String'. >> 'Public Sub New(stream As System.IO.Stream)': Value of type >> 'System.IO.FileInfo' cannot be converted to 'System.IO.Stream'. > > > >> plus i see no where to pass the text i want to write to the file >> >> any help? > > I don't see it, too. ;-) > > sw.writeline("yadda") > > > There are several ways to write to a file. For example: > > Using fs = fi.Open(FileMode.Append, FileAccess.Write, > FileShare.Read) > Using sw As New StreamWriter(fs, System.Text.Encoding.Default) > sw.WriteLine("abc") > End Using > End Using > > > Or, if you just want to open, write, close a/to a file: > > File.AppendAllText(Path, "abc", System.Text.Encoding.Default) > > > -- > Armin Hi Armin, That last line is how i've been doing it previously. when the elearning lesson said it should be the other way i thought i'd try that. ' 'Start e-learning question '****************** 'You are developing a logging module for a large application by using the '.NET Framework. 'You need to append logging information to a file named application.log. This 'log file is opened when the application is started and is closed only when 'the application is closed. However, you append text several times to the 'file during a session. 'You must minimize overhead to the logging process to ensure maximum 'performance. 'Which code segment should you use to create the log file? 'a. StreamWriter sw = File.CreateText(@"c:\application.log"); 'b. FileInfo fi = new FileInfo(@"c:\application.log"); ' FileStream fs = fi.Open(FileMode.Append); 'c. StreamWriter sw = File.AppendText(@"c:\application.log"); 'd. FileInfo fi = new FileInfo(@"c:\application.log"); ' StreamWriter sw = fi.AppendText(); it said the correct answer was d. ps, what is the meaning of @ in those arguments? thanks mark
From: mp on 10 Jun 2010 23:08 "mp" <nospam(a)thanks.com> wrote in message news:hus7uf$7ht$1(a)news.eternal-september.org... > > "Armin Zingler" <az.nospam(a)freenet.de> wrote in message > news:OLzJ2wQCLHA.3880(a)TK2MSFTNGP04.phx.gbl... >> Am 11.06.2010 03:16, schrieb mp: >>> according to online elearning (ms) >>> to write to a debug log use the following: >>> 'd. FileInfo fi = new FileInfo(@"c:\application.log"); SNIP >> >> There are several ways to write to a file. For example: >> >> Using fs = fi.Open(FileMode.Append, FileAccess.Write, >> FileShare.Read) >> Using sw As New StreamWriter(fs, System.Text.Encoding.Default) >> sw.WriteLine("abc") >> End Using >> End Using >> cuious what's the difference between that and just doing Dim sw As StreamWriter = New StreamWriter(m_DebugFileName, True) sw.WriteLine(strMsg) sw.Close() what is the FileInfo object doing other than passing the filename which you already have?
From: Armin Zingler on 11 Jun 2010 07:55 Am 11.06.2010 05:08, schrieb mp: >>> There are several ways to write to a file. For example: >>> >>> Using fs = fi.Open(FileMode.Append, FileAccess.Write, >>> FileShare.Read) >>> Using sw As New StreamWriter(fs, System.Text.Encoding.Default) >>> sw.WriteLine("abc") >>> End Using >>> End Using >>> > > cuious what's the difference between that and just doing > > Dim sw As StreamWriter = New StreamWriter(m_DebugFileName, True) > > sw.WriteLine(strMsg) > > sw.Close() > > what is the FileInfo object doing other than passing the filename which you > already have? Nothing special. Just took it because you've mentioned it before. If you don't need 'fi', just use the path (String). -- Armin
|
Next
|
Last
Pages: 1 2 Prev: in dotnet ide can you return to previous position Next: VB copy files from one folder to other |