Append Time Stamp to Text File VB.Net

~OSD~ 2,126 Reputation points
2022-09-07T10:24:46.867+00:00

Hi,

I have a text file at C:\Windows\Demo.txt
Would like to append the time stamp at the end of the text file with conditions that if file is currently in use by another process, skip the append operation and if it's available append it immediately and close the file.
Is it possible /supported in VB.Net?

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,606 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,570 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 112.1K Reputation points
    2022-09-07T10:57:46.213+00:00

    For example, you can do this:

    Try  
        File.AppendAllText("C:\Windows\Demo.txt", DateTime.Now.ToString() & Environment.NewLine)  
    Catch exc As IOException When exc.HResult = &H80070020  
        ' ignore  
    End Try  
    

    Make sure that you have rights to write to Windows directory.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful