|
-
Aug 6th, 2009, 06:06 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Write a string to a filestream?
My goal is to upload a string to a txt file on an ftp server.
Here is what I have found so far:
vb Code:
Dim clsRequest As System.Net.FtpWebRequest = _
DirectCast(System.Net.WebRequest.Create(RemoteFilename), System.Net.FtpWebRequest)
clsRequest.Credentials = New System.Net.NetworkCredential("usr", "pw")
clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
'write the string to a local text file
Dim Report as String = "Test Report"
Dim ReportFile As String = "C:\report.txt"
Dim strWriter As IO.StreamWriter
strWriter = New IO.StreamWriter(ReportFile)
strWriter.Write(Report)
strWriter.Close()
' read in file
Dim bFile() As Byte = System.IO.File.ReadAllBytes(ReportFile)
' upload file
Dim clsStream As System.IO.Stream = clsRequest.GetRequestStream()
clsStream.Write(bFile, 0, bFile.Length)
clsStream.Close()
clsStream.Dispose()
It seems pretty silly to do it like this! (write the file and then immediately read it again). Is there a way to convert a String into something that clsStream.Write will accept?
Thanks,
Dave
-
Aug 6th, 2009, 06:17 PM
#2
Re: Write a string to a filestream?
Cant you just do:
vb Code:
System.Text.Encoding.ASCII.GetBytes("Some string here")
or does that not work in this case? (I've not played with streams and bytes much to be honest so I'm kind of guessing there...)
-
Aug 6th, 2009, 06:26 PM
#3
Thread Starter
Hyperactive Member
Re: Write a string to a filestream?
It works just fine, I just didn't know about that 
Thanks,
Dave
-
Aug 6th, 2009, 06:28 PM
#4
Re: [RESOLVED] Write a string to a filestream?
Cool, glad to hear it works
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|