Ai pessoal, eh o seguinte:
Estou trabalhando em um projeto que utiliza o vb.net.... preciso criar uma forma de pegar o texto que está em um textbox, ecreve-lo em um txt e dispomibiliza-lo para download. No c# utiliza-se o oStreamWriter, creio que no vb eh a mesma coisa porém com algumas alterações.... ~
Valew!

Dúvida Vb.net
Started By chiforinpola, 05/03/2004, 08:46
1 reply to this topic
#1
Posted 05/03/2004, 08:46
"A vingança nunca é plena, mata a alma e a envenena!"
#2
Posted 08/03/2004, 18:56
mano, vou postar uns exemplos q eu peguei na documentação do framework, qualquer dúvida é só postar:
é isso ai, espero q algum destes exeplos te ajude, se prtecisar de ajuda é só postar
t+
Imports System Imports System.IO Class TestAppend Public Shared Sub Main() ' Append the text from MyFile.txt to this file. Dim output As TextWriter = File.AppendText("c:\NewFile.txt") ' Append text from this file to NewFile.txt. Dim input As TextReader = File.OpenText("c:\MyFile.txt") Dim line As String line = input.ReadLine() While Not (line Is Nothing) output.WriteLine(line) line = input.ReadLine() End While input.Close() output.Close() End Sub End Class
Imports System Imports System.IO Imports System.IO.IsolatedStorage Public Module modmain Sub Main() ' Get an isolated store for this assembly and put it into an ' IsolatedStoreFIle object. Dim isoStore As IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or IsolatedStorageScope.Assembly, Nothing, Nothing) ' This code checks to see if the file already exists. Dim filenames As String() filenames = isoStore.GetFileNames("TestStore.txt") Dim file As String For Each file In filenames If file = "TestStore.txt" Then Console.WriteLine("The file already exists!") Console.WriteLine("Type ""StoreAdm /REMOVE"" at the command line to delete all Isolated Storage for this user.") Exit Sub End If Next WriteToFile(isoStore) Console.WriteLine("The file ""TestStore.txt"" contains:") ' Call readFromFile and write the returned string to the console. Console.WriteLine(ReadFromFile(isoStore)) End Sub ' This method writes "Hello Isolated Storage" to the file. Private Sub WriteToFile(ByVal isoStore As IsolatedStorageFile) ' Declare a new StreamWriter. Dim writer As New StreamWriter(New IsolatedStorageFileStream("TestStore.txt", FileMode.CreateNew, isoStore)) ' Have the writer write "Hello Isolated Storage" to the store. writer.WriteLine("Hello Isolated Storage") writer.Close() Console.WriteLine("You have written to the file.") End Sub ' This method reads the first line in the "TestStore.txt" file. Private Function ReadFromFile(ByVal isoStore As IsolatedStorageFile) As String ' This code opens the TestStore.txt file and reads the string. Dim reader As New StreamReader(New IsolatedStorageFileStream("TestStore.txt", FileMode.Open, isoStore)) ' Read a line from the file and add it to sb. Dim sb As String sb = reader.ReadLine ' Close the reader. reader.Close() Return sb End Function End Module
Imports System Imports System.IO Public Class MoveToTest Public Shared Sub Main() Dim fi As New FileInfo("temp.txt") Dim sw As StreamWriter = fi.AppendText() ' create a reference to a file, which may or may not exist ' if it doesn't exist, it is not yet created ' create a writer, ready to add entries to the file sw.WriteLine("Add as many lines as you like...") sw.WriteLine("Add another line to the output...") sw.Flush() sw.Close() If File.Exists("newTemp.txt") Then ' ensure the target file doesn't exist, since this is disallowed... File.Delete("newTemp.txt") End If ' move this file to ANOTHER file. fi.MoveTo("newTemp.txt") Dim sr As New StreamReader(fi.OpenRead()) ' get the information out of the new file, and print it to screen Console.WriteLine("{0}This is the information in the new file, '{1}':", Environment.NewLine, fi.Name) While sr.Peek() <> - 1 Console.WriteLine(sr.ReadLine()) End While End Sub 'Main End Class 'MoveToTest
Imports System Imports System.IO Public Class CopyToTest Public Shared Sub Main() Dim fi As New FileInfo("temp.txt") Dim sw As StreamWriter = fi.AppendText() ' create a reference to a file, which may or may not exist ' if it doesn't exist, it is not yet created ' create a writer, ready to add entries to the file sw.WriteLine("Add as many lines as you like...") sw.WriteLine("Add another line to the output...") sw.Flush() sw.Close() Dim sr As New StreamReader(fi.OpenRead()) ' get the information out of the file, and print it to screen Console.WriteLine("This is the information in the first file:") While sr.Peek() <> - 1 Console.WriteLine(sr.ReadLine()) End While Dim newfi As FileInfo = fi.CopyTo("newTemp.txt", True) ' copy this file to ANOTHER file. The true parameter indicates ' to overwrite the file if it already exists ' get the information out of the new file, and print it to screen sr = New StreamReader(newfi.OpenRead()) Console.WriteLine("{0}This is the information in the second file:", Environment.NewLine) While sr.Peek() <> - 1 Console.WriteLine(sr.ReadLine()) End While End Sub 'Main End Class 'CopyToTest
é isso ai, espero q algum destes exeplos te ajude, se prtecisar de ajuda é só postar
t+
1 user(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)