[help] Write a text file to a server

Posts 1–15 of 23 · Page 1 of 2
[help] Write a text file to a server
hey guys im making a shoutbox that uses webclient to read and download the textfile. and a timer to refresh.

i have a few questions

  1. How would i write the textfile from my program
  2. how do i hide the textfile from users (such as change file location my method will be below)


my downlaod method

Code:
WebClient1.DownloadFileAsync(New Uri("http://mysite/chat.txt"), "chat.txt")
my read method

Code:
Private Sub WebClient1_DownloadFileCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles WebClient1.DownloadFileCompleted

        Dim read As String = My.Computer.FileSystem.ReadAllText("ragenews.txt")

        TextBox3.Text = "" & read & ""


    End Sub
how would i write to a text file on a server?

and how would i hide the file so people cant edit the text file when it dl's
Download, write the text, and upload.
how would i upload it?
Upload:
Code:
My.Computer.Network.UploadFile(FileLocation, FTPlocation, FTPUsername, FTPPassword, False, 1000000, True)
Download:
Code:
My.Computer.Network.DownloadFile(FTPLocation, DownloadLocation, FTPUsername, FTPPassword, False, 1000000, True)
so it would be like this

My.Computer.Network.UploadFile(chat.txt,c:/, chat, password, False, 1000000, True)
It would look something like this:

Code:
My.Computer.Network.UploadFile("C:\test.txt", "ftp:/www.test.com/testfile.txt",  "username", "password", False, 1000000, True)
That will upload C:\test.txt to www.test.com/testfile.txt.
tyvm loland

you have revived +1 rep
So it's solved?
actuly one more thing

how would i add this in to it?

My.Computer.FileSystem.CurrentDirectory
What do you mean?
nvm

but i get this
Code:
ftp.mysite.com/chat.txt is not a valid remote file address. A valid address should include a protocol, a path and a file name.
Parameter name: address

this is my chat source

Code:
   Private Sub WebClient2_DownloadFileCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles WebClient2.DownloadFileCompleted

        Dim read As String = My.Computer.FileSystem.ReadAllText("chat.txt")

        TextBox4.Text = "" & read & ""


    End Sub
    
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim FILE_NAME As String = "My.Computer.FileSystem.CurrentDirectory\chat.txt"

        If System.IO.File.Exists(FILE_NAME) = True Then
            Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
            objWriter.Write(TextBox4.Text)
            objWriter.Close()
        End If
        '@@@@@@@@@@@@@@@@@@@-------------------------------------------------------------------------@@@@@@@@@
        My.Computer.Network.UploadFile("My.Computer.FileSystem.CurrentDirectory\chat.txt", "ftp.mysite.com/chat.txt", "chat@mysite.com", "pass", False, 1000000, True)

    End Sub
You have to include the "ftp://" protocol before your site.

So something like "ftp://mysite.com/test.txt"
ok, i will try that and then get back to you
ok when i click send, i look's like it send's but the file is blank


Code:
 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim FILE_NAME As String = "c:\chat.txt"

        If System.IO.File.Exists(FILE_NAME) = True Then
            Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
            objWriter.Write(TextBox4.Text)
            objWriter.Close()
        End If
        '@@@@@@@@@@@@@@@@@@@-------------------------------------------------------------------------@@@@@@@@@
        My.Computer.Network.UploadFile("c:\chat.txt", "ftp://mysite.com/chat.txt", "chat@mysite.com", "pass", False, 1000000, True)

    End Sub
Posts 1–15 of 23 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?