Question Best Method to Append Text to a Remote Text File?

digitaldrew

Well-known member
Joined
Nov 10, 2012
Messages
167
Programming Experience
Beginner
Hey everyone. What I am trying to do is write a line (string) to a remote text file on my web server everytime a "success" is returned. I've tried this using streamwriter but that doesn't like me using the remote location (www.mydomain.com/file.txt) since it isn't local.

After reading some more I've found that WebClient and Httpwebrequest may be the two routes I should be looking at going. Problem is, I want to append this text everytime on a new line and not overwrite the file. From my understanding, WebClient won't be able to do this..

I've tried doing this with Httpwebrequest and it doesn't actually write anything to the text file. Any help would be appreciated!
 
You can't write to an existing file on a remote server like that. All you can do is upload an entire file. If you want to add a line to that file then you would have to download the entire file, add a new line to the contents and then upload the new contents. If you want to actually just write the new data then you will need a web service. The web service is an application on that remote server, so it can write to the file because it is local. You call the web service and pass the new data and the web service appends it to the file just like any other .NET app would append to a local file.
 
Thanks for that information JM...I was reading some more about this last night and was starting to come to the same conclusion that this just won't be possible without either uploading the entire file from their computer or looking into a web service..Thanks again!
 
Back
Top