Search code examples
php.netvb.netfopenfwrite

What is VB.NET version of PHP's fopen and fwrite, if one exists?


I am brand new to .NET and developing as a whole, so please bear with me. I've been researching a chat application and found a great tutorial using PHP and Ajax. I've worked around most of it using VB.NET, but can't seem to find out out to set up a type of 'fopen/fwrite'. Hopefully this makes sense. Here is the PHP code I'm trying to 'convert':

  <?  
session_start();  
if(isset($_SESSION['name'])){  
    $text = $_POST['text'];  

    $fp = fopen("log.html", 'a');  
    fwrite($fp, "<div class='msgln'>(".date("g:i A").") <b>".$_SESSION['name']."</b>: ".stripslashes(htmlspecialchars($text))."<br></div>");  
    fclose($fp);  
}  
?> 

If you need any additional info please let me know. Again, only been programming for 4 months now, after doing sales & marketing for 12 years. THANKS!


Solution

  • File.AppendAllText probably comes closest to what you actually want.

    But to answer your question: File.AppendText will create a StreamWriter on the file, so the verbatim translation would be:

    Using writer As StreamWriter = File.AppendText("log.html")
        writer.Write(...)
    End Using
    

    Which is pretty much exactly what the method mentioned above does (apologies if I got the syntax slightly wrong, I didn't write VB.NET in about a decade).