diff --git a/snippets/fsharp/System.IO/File/AppendAllLines/fs.fsproj b/snippets/fsharp/System.IO/File/AppendAllLines/fs.fsproj
new file mode 100644
index 00000000000..36cf252c6c2
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/AppendAllLines/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/AppendAllLines/program.fs b/snippets/fsharp/System.IO/File/AppendAllLines/program.fs
new file mode 100644
index 00000000000..b3644b470b1
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/AppendAllLines/program.fs
@@ -0,0 +1,36 @@
+module program
+//
+open System
+open System.IO
+
+let dataPath = @"c:\temp\timestamps.txt"
+
+let createSampleFile () =
+ let timeStamp = DateTime(1700, 1, 1)
+
+ use sw = new StreamWriter(dataPath)
+
+ for i = 0 to 499 do
+ let ts1 = timeStamp.AddYears i
+ let ts2 = ts1.AddMonths i
+ let ts3 = ts2.AddDays i
+ ts3.ToLongDateString() |> sw.WriteLine
+
+createSampleFile ()
+
+let julyWeekends =
+ File.ReadLines dataPath
+ |> Seq.filter (fun line ->
+ (line.StartsWith "Saturday"
+ || line.StartsWith "Sunday")
+ && line.Contains "July")
+
+File.WriteAllLines(@"C:\temp\selectedDays.txt", julyWeekends)
+
+let marchMondays =
+ File.ReadLines dataPath
+ |> Seq.filter (fun line -> line.StartsWith "Monday" && line.Contains "March")
+
+File.AppendAllLines(@"C:\temp\selectedDays.txt", marchMondays)
+
+//
diff --git a/snippets/fsharp/System.IO/File/AppendAllText/AllText.fs b/snippets/fsharp/System.IO/File/AppendAllText/AllText.fs
new file mode 100644
index 00000000000..001f8988c90
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/AppendAllText/AllText.fs
@@ -0,0 +1,26 @@
+module AllText
+//
+open System
+open System.IO
+
+let path = @"c:\temp\MyTest.txt"
+
+// This text is added only once to the file.
+if File.Exists path |> not then
+ // Create a file to write to.
+ let createText =
+ "Hello and Welcome" + Environment.NewLine
+
+ File.WriteAllText(path, createText)
+
+// This text is always added, making the file longer over time
+// if it is not deleted.
+let appendText =
+ "This is extra text" + Environment.NewLine
+
+File.AppendAllText(path, appendText)
+
+// Open the file to read from.
+let readText = File.ReadAllText path
+printfn $"{readText}"
+//
diff --git a/snippets/fsharp/System.IO/File/AppendAllText/AllText1.fs b/snippets/fsharp/System.IO/File/AppendAllText/AllText1.fs
new file mode 100644
index 00000000000..5c480787bca
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/AppendAllText/AllText1.fs
@@ -0,0 +1,27 @@
+module AllText1
+//
+open System
+open System.IO
+open System.Text
+
+let path = @"c:\temp\MyTest.txt"
+
+// This text is added only once to the file.
+if File.Exists path |> not then
+ // Create a file to write to.
+ let createText =
+ "Hello and Welcome" + Environment.NewLine
+
+ File.WriteAllText(path, createText, Encoding.UTF8)
+
+// This text is always added, making the file longer over time
+// if it is not deleted.
+let appendText =
+ "This is extra text" + Environment.NewLine
+
+File.AppendAllText(path, appendText, Encoding.UTF8)
+
+// Open the file to read from.
+let readText = File.ReadAllText path
+printfn $"{readText}"
+//
diff --git a/snippets/fsharp/System.IO/File/AppendAllText/fs.fsproj b/snippets/fsharp/System.IO/File/AppendAllText/fs.fsproj
new file mode 100644
index 00000000000..554e39f6a3d
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/AppendAllText/fs.fsproj
@@ -0,0 +1,11 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/AppendText/file_appendtext.fs b/snippets/fsharp/System.IO/File/AppendText/file_appendtext.fs
new file mode 100644
index 00000000000..25edbb0b860
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/AppendText/file_appendtext.fs
@@ -0,0 +1,32 @@
+module file_appendtext
+//
+open System.IO
+
+let path = @"c:\temp\MyTest.txt"
+
+// This text is added only once to the file.
+if File.Exists path |> not then
+ // Create a file to write to.
+ use sw = File.CreateText path
+ sw.WriteLine "Hello"
+ sw.WriteLine "And"
+ sw.WriteLine "Welcome"
+
+// This text is always added, making the file longer over time
+// if it is not deleted.
+do
+ use sw = File.AppendText path
+ sw.WriteLine "This"
+ sw.WriteLine "is Extra"
+ sw.WriteLine "Text"
+
+// Open the file to read from.
+do
+ use sr = File.OpenText path
+
+ let mutable s = sr.ReadLine()
+
+ while isNull s |> not do
+ printfn $"{s}"
+ s <- sr.ReadLine()
+//
diff --git a/snippets/fsharp/System.IO/File/AppendText/fs.fsproj b/snippets/fsharp/System.IO/File/AppendText/fs.fsproj
new file mode 100644
index 00000000000..e535e5a6caf
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/AppendText/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/Copy/fs.fsproj b/snippets/fsharp/System.IO/File/Copy/fs.fsproj
new file mode 100644
index 00000000000..36cf252c6c2
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/Copy/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/Copy/program.fs b/snippets/fsharp/System.IO/File/Copy/program.fs
new file mode 100644
index 00000000000..6965238da99
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/Copy/program.fs
@@ -0,0 +1,44 @@
+open System.IO
+
+//
+let sourceDir = @"c:\current"
+let backupDir = @"c:\archives\2008"
+
+try
+ let picList = Directory.GetFiles(sourceDir, "*.jpg")
+ let txtList = Directory.GetFiles(sourceDir, "*.txt")
+
+ // Copy picture files.
+ for f in picList do
+ // Remove path from the file name.
+ let fName = f.Substring(sourceDir.Length + 1)
+
+ // Use the Path.Combine method to safely append the file name to the path.
+ // Will overwrite if the destination file already exists.
+ File.Copy(Path.Combine(sourceDir, fName), Path.Combine(backupDir, fName), true)
+
+ // Copy text files.
+ for f in txtList do
+ // Remove path from the file name.
+ let fName = f.Substring(sourceDir.Length + 1)
+
+ try
+ // Will not overwrite if the destination file already exists.
+ File.Copy(Path.Combine(sourceDir, fName), Path.Combine(backupDir, fName))
+
+ // Catch exception if the file was already copied.
+ with
+ | :? IOException as copyError -> printfn $"{copyError.Message}"
+
+ // Delete source files that were copied.
+ for f in txtList do
+ File.Delete f
+
+ for f in picList do
+ File.Delete f
+
+// Catch exception if the file was already copied.
+with
+| :? DirectoryNotFoundException as dirNotFound -> printfn $"{dirNotFound.Message}"
+
+//
diff --git a/snippets/fsharp/System.IO/File/Create/file create1.fs b/snippets/fsharp/System.IO/File/Create/file create1.fs
new file mode 100644
index 00000000000..d580f456fc6
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/Create/file create1.fs
@@ -0,0 +1,27 @@
+module filecreate1
+
+//
+open System.IO
+open System.Text
+
+let path = @"c:\temp\MyTest.txt"
+
+// Create the file, or overwrite if the file exists.
+do
+ use fs = File.Create path
+
+ let info =
+ UTF8Encoding(true)
+ .GetBytes "This is some text in the file."
+ // Add some information to the file.
+ fs.Write(info, 0, info.Length)
+
+// Open the stream and read it back.
+do
+ use sr = File.OpenText path
+ let mutable s = sr.ReadLine()
+
+ while isNull s |> not do
+ printfn $"{s}"
+ s <- sr.ReadLine()
+//
diff --git a/snippets/fsharp/System.IO/File/Create/file create2.fs b/snippets/fsharp/System.IO/File/Create/file create2.fs
new file mode 100644
index 00000000000..6360c0a4b9d
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/Create/file create2.fs
@@ -0,0 +1,27 @@
+module filecreate2
+
+//
+open System.IO
+open System.Text
+
+let path = @"c:\temp\MyTest.txt"
+
+// Create the file, or overwrite if the file exists.
+do
+ use fs = File.Create(path, 1024)
+
+ let info =
+ UTF8Encoding(true)
+ .GetBytes "This is some text in the file."
+ // Add some information to the file.
+ fs.Write(info, 0, info.Length)
+
+// Open the stream and read it back.
+do
+ use sr = File.OpenText path
+ let mutable s = sr.ReadLine()
+
+ while isNull s |> not do
+ printfn $"{s}"
+ s <- sr.ReadLine()
+//
diff --git a/snippets/fsharp/System.IO/File/Create/fs.fsproj b/snippets/fsharp/System.IO/File/Create/fs.fsproj
new file mode 100644
index 00000000000..f7418dec459
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/Create/fs.fsproj
@@ -0,0 +1,11 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/CreateText/file createtext.fs b/snippets/fsharp/System.IO/File/CreateText/file createtext.fs
new file mode 100644
index 00000000000..bbcd5c30bd8
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/CreateText/file createtext.fs
@@ -0,0 +1,22 @@
+module filecreatetext
+
+//
+open System.IO
+
+let path = @"c:\temp\MyTest.txt"
+
+if File.Exists path |> not then
+ // Create a file to write to.
+ use sw = File.CreateText path
+ sw.WriteLine "Hello"
+ sw.WriteLine "Welcome"
+
+// Open the file to read from.
+do
+ use sr = File.OpenText path
+ let mutable s = sr.ReadLine()
+
+ while isNull s |> not do
+ printfn $"{s}"
+ s <- sr.ReadLine()
+//
diff --git a/snippets/fsharp/System.IO/File/CreateText/fs.fsproj b/snippets/fsharp/System.IO/File/CreateText/fs.fsproj
new file mode 100644
index 00000000000..36dff980b92
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/CreateText/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/Decrypt/fs.fsproj b/snippets/fsharp/System.IO/File/Decrypt/fs.fsproj
new file mode 100644
index 00000000000..3303de996c4
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/Decrypt/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/Decrypt/sample.fs b/snippets/fsharp/System.IO/File/Decrypt/sample.fs
new file mode 100644
index 00000000000..4031c46451c
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/Decrypt/sample.fs
@@ -0,0 +1,23 @@
+//
+open System.IO
+
+// Encrypt a file.
+let addEncryption fileName = File.Encrypt fileName
+
+// Decrypt a file.
+let removeEncryption fileName = File.Decrypt fileName
+
+let fileName = "test.xml"
+
+printfn $"Encrypt {fileName}"
+
+// Encrypt the file.
+addEncryption fileName
+
+printfn $"Decrypt {fileName}"
+
+// Decrypt the file.
+removeEncryption fileName
+
+printfn "Done"
+//
diff --git a/snippets/fsharp/System.IO/File/Exists/fs.fsproj b/snippets/fsharp/System.IO/File/Exists/fs.fsproj
new file mode 100644
index 00000000000..36cf252c6c2
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/Exists/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/Exists/program.fs b/snippets/fsharp/System.IO/File/Exists/program.fs
new file mode 100644
index 00000000000..c3db09c561c
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/Exists/program.fs
@@ -0,0 +1,11 @@
+open System.IO
+
+//
+let curFile = @"c:\temp\test.txt"
+
+printfn
+ $"""{if File.Exists curFile then
+ "File exists."
+ else
+ "File does not exist."}"""
+//
diff --git a/snippets/fsharp/System.IO/File/GetAccessControl/fs.fsproj b/snippets/fsharp/System.IO/File/GetAccessControl/fs.fsproj
new file mode 100644
index 00000000000..4b3b27f8055
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/GetAccessControl/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net48
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/GetAccessControl/sample.fs b/snippets/fsharp/System.IO/File/GetAccessControl/sample.fs
new file mode 100644
index 00000000000..820cd6686cd
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/GetAccessControl/sample.fs
@@ -0,0 +1,44 @@
+//
+open System.IO
+open System.Security.AccessControl
+
+// Adds an ACL entry on the specified file for the specified account.
+let addFileSecurity fileName (account: string) rights controlType =
+ // Get a FileSecurity object that represents the
+ // current security settings.
+ let fSecurity = File.GetAccessControl fileName
+
+ // Add the FileSystemAccessRule to the security settings.
+ FileSystemAccessRule(account, rights, controlType)
+ |> fSecurity.AddAccessRule
+
+ // Set the new access settings.
+ File.SetAccessControl(fileName, fSecurity)
+
+// Removes an ACL entry on the specified file for the specified account.
+let removeFileSecurity fileName (account: string) rights controlType =
+ // Get a FileSecurity object that represents the
+ // current security settings.
+ let fSecurity = File.GetAccessControl fileName
+
+ // Remove the FileSystemAccessRule from the security settings.
+ fSecurity.RemoveAccessRule(FileSystemAccessRule(account, rights, controlType))
+ |> ignore
+
+ // Set the new access settings.
+ File.SetAccessControl(fileName, fSecurity)
+
+let fileName = "test.xml"
+
+printfn $"Adding access control entry for {fileName}"
+
+// Add the access control entry to the file.
+addFileSecurity fileName @"DomainName\AccountName" FileSystemRights.ReadData AccessControlType.Allow
+
+printfn $"Removing access control entry from {fileName}"
+
+// Remove the access control entry from the file.
+removeFileSecurity fileName @"DomainName\AccountName" FileSystemRights.ReadData AccessControlType.Allow
+
+printfn "Done."
+//
diff --git a/snippets/fsharp/System.IO/File/GetAttributes/file getattributes.fs b/snippets/fsharp/System.IO/File/GetAttributes/file getattributes.fs
new file mode 100644
index 00000000000..14a537ae7d5
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/GetAttributes/file getattributes.fs
@@ -0,0 +1,27 @@
+module filegetattributes
+//
+open System.IO
+open System.Text
+
+let removeAttribute attributes attributesToRemove = attributes &&& ~~~attributesToRemove
+
+let path = @"c:\temp\MyTest.txt"
+
+// Create the file if it does not exist.
+if File.Exists path |> not then
+ File.Create path |> ignore
+
+let attributes = File.GetAttributes path
+
+if attributes &&& FileAttributes.Hidden = FileAttributes.Hidden then
+ // Show the file.
+ let attributes =
+ removeAttribute attributes FileAttributes.Hidden
+
+ File.SetAttributes(path, attributes)
+ printfn $"The {path} file is no longer hidden."
+else
+ // Hide the file.
+ File.SetAttributes(path, File.GetAttributes path ||| FileAttributes.Hidden)
+ printfn $"The {path} file is now hidden."
+//
diff --git a/snippets/fsharp/System.IO/File/GetAttributes/fs.fsproj b/snippets/fsharp/System.IO/File/GetAttributes/fs.fsproj
new file mode 100644
index 00000000000..48cb918e5d9
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/GetAttributes/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/GetLastAccessTime/file getlastaccess.fs b/snippets/fsharp/System.IO/File/GetLastAccessTime/file getlastaccess.fs
new file mode 100644
index 00000000000..41ad6198244
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/GetLastAccessTime/file getlastaccess.fs
@@ -0,0 +1,21 @@
+module filegetlastaccess
+//
+open System
+open System.IO
+
+let path = @"c:\Temp\MyTest.txt"
+
+if File.Exists path |> not then
+ File.Create path |> ignore
+
+File.SetLastAccessTime(path, DateTime(1985, 5, 4))
+
+// Get the creation time of a well-known directory.
+let dt = File.GetLastAccessTime path
+printfn $"The last access time for this file was {dt}."
+
+// Update the last access time.
+File.SetLastAccessTime(path, DateTime.Now)
+let dt2 = File.GetLastAccessTime path
+printfn $"The last access time for this file was {dt2}."
+//
diff --git a/snippets/fsharp/System.IO/File/GetLastAccessTime/fs.fsproj b/snippets/fsharp/System.IO/File/GetLastAccessTime/fs.fsproj
new file mode 100644
index 00000000000..bfa164acccc
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/GetLastAccessTime/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/GetLastWriteTime/file getlastwrite.fs b/snippets/fsharp/System.IO/File/GetLastWriteTime/file getlastwrite.fs
new file mode 100644
index 00000000000..8e0a35131d7
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/GetLastWriteTime/file getlastwrite.fs
@@ -0,0 +1,22 @@
+module filegetlastwrite
+//
+open System
+open System.IO
+
+let path = @"c:\Temp\MyTest.txt"
+
+if File.Exists path |> not then
+ File.Create path |> ignore
+else
+ // Take an action that will affect the write time.
+ File.SetLastWriteTime(path, DateTime(1985, 4, 3))
+
+// Get the creation time of a well-known directory.
+let dt = File.GetLastWriteTime path
+printfn $"The last write time for this file was {dt}."
+
+// Update the last write time.
+File.SetLastWriteTime(path, DateTime.Now)
+let dt2 = File.GetLastWriteTime path
+printfn $"The last write time for this file was {dt2}."
+//
diff --git a/snippets/fsharp/System.IO/File/GetLastWriteTime/fs.fsproj b/snippets/fsharp/System.IO/File/GetLastWriteTime/fs.fsproj
new file mode 100644
index 00000000000..4b7f4bee82d
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/GetLastWriteTime/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/Move/file move.fs b/snippets/fsharp/System.IO/File/Move/file move.fs
new file mode 100644
index 00000000000..7de60b4d5dc
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/Move/file move.fs
@@ -0,0 +1,27 @@
+module filemove
+//
+open System.IO
+
+let path = @"c:\temp\MyTest.txt"
+let path2 = @"c:\temp2\MyTest.txt"
+
+if File.Exists path |> not then
+ // This statement ensures that the file is created,
+ // but the handle is not kept.
+ use _ = File.Create path
+ ()
+
+// Ensure that the target does not exist.
+if File.Exists path2 then
+ File.Delete path2
+
+// Move the file.
+File.Move(path, path2)
+printfn $"{path} was moved to {path2}."
+
+// See if the original exists now.
+if File.Exists path then
+ printfn "The original file still exists, which is unexpected."
+else
+ printfn "The original file no longer exists, which is expected."
+//
diff --git a/snippets/fsharp/System.IO/File/Move/fs.fsproj b/snippets/fsharp/System.IO/File/Move/fs.fsproj
new file mode 100644
index 00000000000..33a0fcc24c1
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/Move/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/Open/file open1.fs b/snippets/fsharp/System.IO/File/Open/file open1.fs
new file mode 100644
index 00000000000..196869087ad
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/Open/file open1.fs
@@ -0,0 +1,27 @@
+module fileopen1
+//
+open System.IO
+open System.Text
+
+// Create a temporary file, and put some data into it.
+let path = Path.GetTempFileName()
+
+do
+ use fs =
+ File.Open(path, FileMode.Open, FileAccess.Write, FileShare.None)
+
+ let info =
+ UTF8Encoding(true)
+ .GetBytes "This is some text in the file."
+ // Add some information to the file.
+ fs.Write(info, 0, info.Length)
+
+// Open the stream and read it back.
+do
+ use fs = File.Open(path, FileMode.Open)
+ let b = Array.zeroCreate 1024
+ let temp = UTF8Encoding true
+
+ while fs.Read(b, 0, b.Length) > 0 do
+ printfn $"{temp.GetString b}"
+//
diff --git a/snippets/fsharp/System.IO/File/Open/file open2.fs b/snippets/fsharp/System.IO/File/Open/file open2.fs
new file mode 100644
index 00000000000..6cab38fbd29
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/Open/file open2.fs
@@ -0,0 +1,39 @@
+module fileopen2
+//
+open System.IO
+open System.Text
+
+// This sample assumes that you have a folder named "c:\temp" on your computer.
+let filePath = @"c:\temp\MyTest.txt"
+
+// Delete the file if it exists.
+if File.Exists filePath then
+ File.Delete filePath
+
+// Create the file.
+do
+ use fs = File.Create filePath
+
+ let info =
+ UTF8Encoding(true)
+ .GetBytes "This is some text in the file."
+ // Add some information to the file.
+ fs.Write(info, 0, info.Length)
+
+// Open the stream and read it back.
+do
+ use fs =
+ File.Open(filePath, FileMode.Open, FileAccess.Read)
+
+ let b = Array.zeroCreate 1024
+ let temp = UTF8Encoding true
+
+ while fs.Read(b, 0, b.Length) > 0 do
+ printfn $"{temp.GetString b}"
+
+ try
+ // Try to write to the file.
+ fs.Write(b, 0, b.Length)
+ with
+ | e -> printfn $"Writing was disallowed, as expected: {e}"
+//
diff --git a/snippets/fsharp/System.IO/File/Open/file open3.fs b/snippets/fsharp/System.IO/File/Open/file open3.fs
new file mode 100644
index 00000000000..246898a09af
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/Open/file open3.fs
@@ -0,0 +1,38 @@
+module fileopen3
+//
+open System.IO
+open System.Text
+
+let path = @"c:\temp\MyTest.txt"
+
+// Create the file if it does not exist.
+if File.Exists path |> not then
+ // Create the file.
+ use fs = File.Create path
+
+ let info =
+ UTF8Encoding(true)
+ .GetBytes "This is some text in the file."
+
+ // Add some information to the file.
+ fs.Write(info, 0, info.Length)
+
+// Open the stream and read it back.
+do
+ use fs =
+ File.Open(path, FileMode.Open, FileAccess.Read, FileShare.None)
+
+ let b = Array.zeroCreate 1024
+ let temp = UTF8Encoding true
+
+ while fs.Read(b, 0, b.Length) > 0 do
+ printfn $"{temp.GetString b}"
+
+ try
+ // Try to get another handle to the same file.
+ use fs2 = File.Open(path, FileMode.Open)
+ // Do some task here.
+ ()
+ with
+ | e -> printf "Opening the file twice is disallowed, as expected: {e}"
+//
diff --git a/snippets/fsharp/System.IO/File/Open/fs.fsproj b/snippets/fsharp/System.IO/File/Open/fs.fsproj
new file mode 100644
index 00000000000..77e714d3320
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/Open/fs.fsproj
@@ -0,0 +1,12 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/OpenRead/file openread.fs b/snippets/fsharp/System.IO/File/OpenRead/file openread.fs
new file mode 100644
index 00000000000..d4cfe052b55
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/OpenRead/file openread.fs
@@ -0,0 +1,27 @@
+module fileopenread
+//
+open System.IO
+open System.Text
+
+let path = @"c:\temp\MyTest.txt"
+
+if File.Exists path |> not then
+ // Create the file.
+ use fs = File.Create path
+
+ let info =
+ UTF8Encoding(true)
+ .GetBytes "This is some text in the file."
+
+ // Add some information to the file.
+ fs.Write(info, 0, info.Length)
+
+// Open the stream and read it back.
+do
+ use fs = File.OpenRead path
+ let b = Array.zeroCreate 1024
+ let temp = UTF8Encoding true
+
+ while fs.Read(b, 0, b.Length) > 0 do
+ printfn $"{temp.GetString b}"
+//
diff --git a/snippets/fsharp/System.IO/File/OpenRead/fs.fsproj b/snippets/fsharp/System.IO/File/OpenRead/fs.fsproj
new file mode 100644
index 00000000000..f650e4a4d64
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/OpenRead/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/OpenText/file opentext.fs b/snippets/fsharp/System.IO/File/OpenText/file opentext.fs
new file mode 100644
index 00000000000..016871522af
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/OpenText/file opentext.fs
@@ -0,0 +1,27 @@
+module fileopentext
+//
+open System.IO
+open System.Text
+
+let path = @"c:\temp\MyTest.txt"
+
+if File.Exists path |> not then
+ // Create the file.
+ use fs = File.Create path
+
+ let info =
+ UTF8Encoding(true)
+ .GetBytes "This is some text in the file."
+
+ // Add some information to the file.
+ fs.Write(info, 0, info.Length)
+
+// Open the stream and read it back.
+do
+ use sr = File.OpenText path
+ let mutable s = sr.ReadLine()
+
+ while isNull s |> not do
+ printfn $"{s}"
+ s <- sr.ReadLine()
+//
diff --git a/snippets/fsharp/System.IO/File/OpenText/fs.fsproj b/snippets/fsharp/System.IO/File/OpenText/fs.fsproj
new file mode 100644
index 00000000000..598dd955adf
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/OpenText/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/OpenWrite/file openwrite.fs b/snippets/fsharp/System.IO/File/OpenWrite/file openwrite.fs
new file mode 100644
index 00000000000..640c464eae9
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/OpenWrite/file openwrite.fs
@@ -0,0 +1,27 @@
+module fileopenwrite
+//
+open System.IO
+open System.Text
+
+let path = @"c:\temp\MyTest.txt"
+
+// Open the stream and write to it.
+do
+ use fs = File.OpenWrite path
+
+ let info =
+ UTF8Encoding(true)
+ .GetBytes "This is to test the OpenWrite method."
+
+ // Add some information to the file.
+ fs.Write(info, 0, info.Length)
+
+// Open the stream and read it back.
+do
+ use fs = File.OpenRead path
+ let b = Array.zeroCreate 1024
+ let temp = UTF8Encoding true
+
+ while fs.Read(b, 0, b.Length) > 0 do
+ printfn $"{temp.GetString b}"
+//
diff --git a/snippets/fsharp/System.IO/File/OpenWrite/fs.fsproj b/snippets/fsharp/System.IO/File/OpenWrite/fs.fsproj
new file mode 100644
index 00000000000..fe469142bd7
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/OpenWrite/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/Overview/file class example.fs b/snippets/fsharp/System.IO/File/Overview/file class example.fs
new file mode 100644
index 00000000000..cf2abda4411
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/Overview/file class example.fs
@@ -0,0 +1,23 @@
+module fileclassexample
+
+//
+open System.IO
+
+let path = @"c:\temp\MyTest.txt"
+
+if File.Exists path |> not then
+ // Create a file to write to.
+ use sw = File.CreateText path
+ sw.WriteLine "Hello"
+ sw.WriteLine "And"
+ sw.WriteLine "Welcome"
+
+// Open the file to read from.
+do
+ use sr = File.OpenText path
+ let mutable s = sr.ReadLine()
+
+ while isNull s |> not do
+ printfn $"{s}"
+ s <- sr.ReadLine()
+//
diff --git a/snippets/fsharp/System.IO/File/Overview/fs.fsproj b/snippets/fsharp/System.IO/File/Overview/fs.fsproj
new file mode 100644
index 00000000000..2ddd923520f
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/Overview/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/ReadAllLines/AllText.fs b/snippets/fsharp/System.IO/File/ReadAllLines/AllText.fs
new file mode 100644
index 00000000000..79a4202a07e
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/ReadAllLines/AllText.fs
@@ -0,0 +1,26 @@
+module alltext
+//
+open System
+open System.IO
+
+let path = @"c:\temp\MyTest.txt"
+
+// This text is added only once to the file.
+if File.Exists path |> not then
+ // Create a file to write to.
+ let createText = [ "Hello"; "And"; "Welcome" ]
+ File.WriteAllLines(path, createText)
+
+// This text is always added, making the file longer over time
+// if it is not deleted.
+let appendText =
+ "This is extra text" + Environment.NewLine
+
+File.AppendAllText(path, appendText)
+
+// Open the file to read from.
+let readText = File.ReadAllLines path
+
+for s in readText do
+ printfn $"{s}"
+//
diff --git a/snippets/fsharp/System.IO/File/ReadAllLines/AllText_Encoding.fs b/snippets/fsharp/System.IO/File/ReadAllLines/AllText_Encoding.fs
new file mode 100644
index 00000000000..62ca0755036
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/ReadAllLines/AllText_Encoding.fs
@@ -0,0 +1,27 @@
+module alltext_encoding
+//
+open System
+open System.IO
+open System.Text
+
+let path = @"c:\temp\MyTest.txt"
+
+// This text is added only once to the file.
+if File.Exists path |> not then
+ // Create a file to write to.
+ let createText = [ "Hello"; "And"; "Welcome" ]
+ File.WriteAllLines(path, createText, Encoding.UTF8)
+
+// This text is always added, making the file longer over time
+// if it is not deleted.
+let appendText =
+ "This is extra text" + Environment.NewLine
+
+File.AppendAllText(path, appendText, Encoding.UTF8)
+
+// Open the file to read from.
+let readText = File.ReadAllLines(path, Encoding.UTF8)
+
+for s in readText do
+ printfn $"{s}"
+//
diff --git a/snippets/fsharp/System.IO/File/ReadAllLines/fs.fsproj b/snippets/fsharp/System.IO/File/ReadAllLines/fs.fsproj
new file mode 100644
index 00000000000..45318a5e120
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/ReadAllLines/fs.fsproj
@@ -0,0 +1,11 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/ReadLines/fs.fsproj b/snippets/fsharp/System.IO/File/ReadLines/fs.fsproj
new file mode 100644
index 00000000000..36cf252c6c2
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/ReadLines/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/ReadLines/program.fs b/snippets/fsharp/System.IO/File/ReadLines/program.fs
new file mode 100644
index 00000000000..7d841b65462
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/ReadLines/program.fs
@@ -0,0 +1,7 @@
+open System.IO
+
+//
+for line in File.ReadLines @"d:\data\episodes.txt" do
+ if line.Contains "episode" && line.Contains "2006" then
+ printfn $"{line}"
+//
diff --git a/snippets/fsharp/System.IO/File/Replace/fs.fsproj b/snippets/fsharp/System.IO/File/Replace/fs.fsproj
new file mode 100644
index 00000000000..3303de996c4
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/Replace/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/Replace/sample.fs b/snippets/fsharp/System.IO/File/Replace/sample.fs
new file mode 100644
index 00000000000..300b1b2a098
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/Replace/sample.fs
@@ -0,0 +1,20 @@
+//
+open System
+open System.IO
+
+// Move a file into another file, delete the original, and create a backup of the replaced file.
+let replaceFile fileToMoveAndDelete fileToReplace backupOfFileToReplace =
+ File.Replace(fileToMoveAndDelete, fileToReplace, backupOfFileToReplace, false)
+
+let originalFile = "test.xml"
+let fileToReplace = "test2.xml"
+let backUpOfFileToReplace = "test2.xml.bac"
+
+printfn
+ $"Move the contents of {originalFile} into {fileToReplace}, delete {originalFile}, and create a backup of {fileToReplace}."
+
+// Replace the file.
+replaceFile originalFile fileToReplace backUpOfFileToReplace
+
+printfn "Done"
+//
diff --git a/snippets/fsharp/System.IO/File/SetLastAccessTime/file setlastaccess.fs b/snippets/fsharp/System.IO/File/SetLastAccessTime/file setlastaccess.fs
new file mode 100644
index 00000000000..bb15d6925b0
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/SetLastAccessTime/file setlastaccess.fs
@@ -0,0 +1,25 @@
+module setlastaccess
+//
+open System
+open System.IO
+
+try
+ let path = @"c:\Temp\MyTest.txt"
+
+ if File.Exists path |> not then
+ File.Create path |> ignore
+
+ // Update the last access time.
+ File.SetLastAccessTime(path, DateTime(1985, 5, 4))
+
+ // Get the creation time of a well-known directory.
+ let dt = File.GetLastAccessTime path
+ printfn $"The last access time for this file was {dt}."
+
+ // Update the last access time.
+ File.SetLastAccessTime(path, DateTime.Now)
+ let dt = File.GetLastAccessTime path
+ printfn $"The last access time for this file was {dt}."
+with
+| e -> printfn $"The process failed: {e}"
+//
diff --git a/snippets/fsharp/System.IO/File/SetLastAccessTime/fs.fsproj b/snippets/fsharp/System.IO/File/SetLastAccessTime/fs.fsproj
new file mode 100644
index 00000000000..6331786e334
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/SetLastAccessTime/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/snippets/fsharp/System.IO/File/SetLastWriteTime/file setlastwrite.fs b/snippets/fsharp/System.IO/File/SetLastWriteTime/file setlastwrite.fs
new file mode 100644
index 00000000000..f879625d7a6
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/SetLastWriteTime/file setlastwrite.fs
@@ -0,0 +1,25 @@
+module filesetlastwrite
+//
+open System
+open System.IO
+
+try
+ let path = @"c:\Temp\MyTest.txt"
+
+ if File.Exists path |> not then
+ File.Create path |> ignore
+ else
+ // Take an action that will affect the write time.
+ File.SetLastWriteTime(path, DateTime(1985, 4, 3))
+
+ // Get the creation time of a well-known directory.
+ let dt = File.GetLastWriteTime path
+ printfn $"The last write time for this file was {dt}."
+
+ // Update the last write time.
+ File.SetLastWriteTime(path, DateTime.Now)
+ let dt = File.GetLastWriteTime path
+ printfn $"The last write time for this file was {dt}."
+with
+| e -> printfn $"The process failed: {e}"
+//
diff --git a/snippets/fsharp/System.IO/File/SetLastWriteTime/fs.fsproj b/snippets/fsharp/System.IO/File/SetLastWriteTime/fs.fsproj
new file mode 100644
index 00000000000..ac02e1ee632
--- /dev/null
+++ b/snippets/fsharp/System.IO/File/SetLastWriteTime/fs.fsproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ net6.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/xml/System.IO/File.xml b/xml/System.IO/File.xml
index 7e5a27f5799..1ce0c946a74 100644
--- a/xml/System.IO/File.xml
+++ b/xml/System.IO/File.xml
@@ -99,6 +99,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/File Class Example/CPP/file class example.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/Overview/file class example.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/Overview/file class example.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/File Class Example/VB/file class example.vb" id="Snippet1":::
]]>
@@ -183,6 +184,7 @@
The following example writes selected lines from a sample data file to a file, and then appends more lines. The directory named `temp` on drive C must exist for the example to complete successfully.
:::code language="csharp" source="~/snippets/csharp/System.IO/File/AppendAllLines/program.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/AppendAllLines/program.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.io.file.writeallappendall/vb/program.vb" id="Snippet1":::
]]>
@@ -471,6 +473,7 @@
The following code example demonstrates the use of the method to add extra text to the end of a file. In this example, a file is created if it doesn't already exist, and text is added to it. However, the directory named `temp` on drive C must exist for the example to complete successfully.
:::code language="csharp" source="~/snippets/csharp/System.IO/File/AppendAllText/AllText.cs" id="Snippet00":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/AppendAllText/AllText.fs" id="Snippet00":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IO.File.AllText/vb/AllText.vb" id="Snippet00":::
]]>
@@ -568,6 +571,7 @@
The following code example demonstrates the use of the method to add extra text to the end of a file. In this example, a file is created if it doesn't already exist, and text is added to it. However, the directory named `temp` on drive C must exist for the example to complete successfully.
:::code language="csharp" source="~/snippets/csharp/System.IO/File/AppendAllText/AllText1.cs" id="Snippet00":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/AppendAllText/AllText1.fs" id="Snippet00":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IO.File.AllText_Encoding/vb/AllText.vb" id="Snippet00":::
]]>
@@ -759,6 +763,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/File_AppendText/CPP/file_appendtext.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/AppendText/file_appendtext.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/AppendText/file_appendtext.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/File_AppendText/VB/file_appendtext.vb" id="Snippet1":::
]]>
@@ -854,6 +859,7 @@
- It then uses the method overload to copy pictures (.jpg files). The code demonstrates that this overload does allow overwriting files that were already copied.
:::code language="csharp" source="~/snippets/csharp/System.IO/File/Copy/program.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/Copy/program.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/filecopydelete/vb/program.vb" id="Snippet1":::
]]>
@@ -956,6 +962,7 @@
It then uses the method overload to copy pictures (.jpg files). The code demonstrates that this overload does allow overwriting files that were already copied.
:::code language="csharp" source="~/snippets/csharp/System.IO/File/Copy/program.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/Copy/program.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/filecopydelete/vb/program.vb" id="Snippet1":::
]]>
@@ -1081,6 +1088,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/File Create1/CPP/file create1.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/Create/file create1.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/Create/file create1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/File Create1/VB/file create1.vb" id="Snippet1":::
]]>
@@ -1182,6 +1190,7 @@
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/File Create2/CPP/file create2.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/Create/file create2.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/Create/file create2.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/File Create2/VB/file create2.vb" id="Snippet1":::
]]>
@@ -1491,6 +1500,7 @@ An I/O error occurred.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/File CreateText/CPP/file createtext.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/CreateText/file createtext.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/CreateText/file createtext.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/File CreateText/VB/file createtext.vb" id="Snippet1":::
]]>
@@ -1590,6 +1600,7 @@ An I/O error occurred.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/IO.File.Encrypt-Decrypt/cpp/sample.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/Decrypt/sample.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/Decrypt/sample.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/IO.File.Encrypt-Decrypt/VB/sample.vb" id="Snippet1":::
]]>
@@ -1687,6 +1698,7 @@ An I/O error occurred.
The following example copies groups of files to the C:\archives\2008 backup folder and then deletes them from the source folder.
:::code language="csharp" source="~/snippets/csharp/System.IO/File/Copy/program.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/Copy/program.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/filecopydelete/vb/program.vb" id="Snippet1":::
]]>
@@ -1795,6 +1807,7 @@ An I/O error occurred.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/IO.File.Encrypt-Decrypt/cpp/sample.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/Decrypt/sample.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/Decrypt/sample.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/IO.File.Encrypt-Decrypt/VB/sample.vb" id="Snippet1":::
]]>
@@ -1908,6 +1921,7 @@ An I/O error occurred.
The following example determines if a file exists.
:::code language="csharp" source="~/snippets/csharp/System.IO/File/Exists/program.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/Exists/program.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/File Exists/VB/program.vb" id="Snippet1":::
]]>
@@ -1986,6 +2000,7 @@ An I/O error occurred.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/IO.File.GetAccessControl-SetAccessControl/cpp/sample.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/GetAccessControl/sample.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/GetAccessControl/sample.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/IO.File.GetAccessControl-SetAccessControl/VB/sample.vb" id="Snippet1":::
]]>
@@ -2173,6 +2188,7 @@ An I/O error occurred.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/File GetAttributes/CPP/file getattributes.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/GetAttributes/file getattributes.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/GetAttributes/file getattributes.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/File GetAttributes/VB/file getattributes.vb" id="Snippet1":::
]]>
@@ -2542,6 +2558,7 @@ An I/O error occurred.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/File GetLastAccess/CPP/file getlastaccess.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/GetLastAccessTime/file getlastaccess.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/GetLastAccessTime/file getlastaccess.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/File GetLastAccess/VB/file getlastaccess.vb" id="Snippet1":::
]]>
@@ -2779,6 +2796,7 @@ An I/O error occurred.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/File GetLastWrite/CPP/file getlastwrite.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/GetLastWriteTime/file getlastwrite.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/GetLastWriteTime/file getlastwrite.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/File GetLastWrite/VB/file getlastwrite.vb" id="Snippet1":::
]]>
@@ -3074,6 +3092,7 @@ The following example moves a file.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/File Move/CPP/file move.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/Move/file move.cs" id="Snippet1":::
+:::code language="fsharp" source="~/snippets/fsharp/System.IO/File/Move/file move.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/File Move/VB/file move.vb" id="Snippet1":::
]]>
@@ -3162,6 +3181,7 @@ The following example moves a file.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/File Move/CPP/file move.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/Move/file move.cs" id="Snippet1":::
+:::code language="fsharp" source="~/snippets/fsharp/System.IO/File/Move/file move.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/File Move/VB/file move.vb" id="Snippet1":::
]]>
@@ -3266,6 +3286,7 @@ The following example moves a file.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/File Open1/CPP/file open1.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/Open/file open1.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/Open/file open1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/File Open1/VB/file open1.vb" id="Snippet1":::
]]>
@@ -3417,6 +3438,7 @@ The following example moves a file.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/File Open2/CPP/file open2.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/Open/file open2.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/Open/file open2.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/File Open2/VB/file open2.vb" id="Snippet1":::
]]>
@@ -3527,6 +3549,7 @@ The following example moves a file.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/File Open3/CPP/file open3.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/Open/file open3.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/Open/file open3.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/File Open3/VB/file open3.vb" id="Snippet1":::
]]>
@@ -3697,6 +3720,7 @@ The following example moves a file.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/File OpenRead/CPP/file openread.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/OpenRead/file openread.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/OpenRead/file openread.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/File OpenRead/VB/file openread.vb" id="Snippet1":::
]]>
@@ -3790,6 +3814,7 @@ The following example moves a file.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/File OpenText/CPP/file opentext.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/OpenText/file opentext.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/OpenText/file opentext.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/File OpenText/VB/file opentext.vb" id="Snippet1":::
]]>
@@ -3881,6 +3906,7 @@ The following example moves a file.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/File OpenWrite/CPP/file openwrite.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/OpenWrite/file openwrite.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/OpenWrite/file openwrite.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/File OpenWrite/VB/file openwrite.vb" id="Snippet1":::
]]>
@@ -4102,6 +4128,7 @@ The following example moves a file.
The following code example demonstrates the use of the method to display the contents of a file. In this example a file is created, if it doesn't already exist, and text is added to it.
:::code language="csharp" source="~/snippets/csharp/System.IO/File/ReadAllLines/AllText.cs" id="Snippet00":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/ReadAllLines/AllText.fs" id="Snippet00":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IO.File.AllLines/vb/AllText.vb" id="Snippet00":::
]]>
@@ -4202,6 +4229,7 @@ The following example moves a file.
The following code example demonstrates the use of the method to display the contents of a file. In this example a file is created, if it doesn't already exist, and text is added to it.
:::code language="csharp" source="~/snippets/csharp/System.IO/File/ReadAllLines/AllText_Encoding.cs" id="Snippet00":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/ReadAllLines/AllText_Encoding.fs" id="Snippet00":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IO.File.AllLines_Encoding/vb/AllText_Encoding.vb" id="Snippet00":::
]]>
@@ -4400,6 +4428,7 @@ The following example moves a file.
The following code example demonstrates the use of the method to display the contents of a file. In this example a file is created, if it doesn't already exist, and text is added to it.
:::code language="csharp" source="~/snippets/csharp/System.IO/File/AppendAllText/AllText.cs" id="Snippet00":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/AppendAllText/AllText.fs" id="Snippet00":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IO.File.AllText/vb/AllText.vb" id="Snippet00":::
]]>
@@ -4504,6 +4533,7 @@ The following example moves a file.
The following code example demonstrates the use of the method to display the contents of a file. In this example a file is created, if it doesn't already exist, and text is added to it.
:::code language="csharp" source="~/snippets/csharp/System.IO/File/AppendAllText/AllText1.cs" id="Snippet00":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/AppendAllText/AllText1.fs" id="Snippet00":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IO.File.AllText_Encoding/vb/AllText.vb" id="Snippet00":::
]]>
@@ -4705,11 +4735,13 @@ The following example moves a file.
The following example reads the lines of a file to find lines that contain specified strings.
:::code language="csharp" source="~/snippets/csharp/System.IO/File/ReadLines/program.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/ReadLines/program.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.io.file.readlines/vb/program.vb" id="Snippet1":::
The following example uses the method in a LINQ query that enumerates all directories for files that have a .txt extension, reads each line of the file, and displays the line if it contains the string "Microsoft".
:::code language="csharp" source="~/snippets/csharp/System.IO/Directory/EnumerateFiles/program.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/Directory/EnumerateFiles/program.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.io.directory.enumeratefiles/vb/program.vb" id="Snippet1":::
]]>
@@ -4984,6 +5016,7 @@ The following example moves a file.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/IO.File.Replace/cpp/sample.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/Replace/sample.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/Replace/sample.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/IO.File.Replace/VB/sample.vb" id="Snippet1":::
]]>
@@ -5099,6 +5132,7 @@ The caller does not have the required permission.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/IO.File.Replace/cpp/sample.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/Replace/sample.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/Replace/sample.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/IO.File.Replace/VB/sample.vb" id="Snippet1":::
]]>
@@ -5269,6 +5303,7 @@ There are too many levels of symbolic links.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/IO.File.GetAccessControl-SetAccessControl/cpp/sample.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/GetAccessControl/sample.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/GetAccessControl/sample.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/IO.File.GetAccessControl-SetAccessControl/VB/sample.vb" id="Snippet1":::
]]>
@@ -5408,6 +5443,7 @@ It is not possible to change the compression status of a o
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/File GetAttributes/CPP/file getattributes.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/GetAttributes/file getattributes.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/GetAttributes/file getattributes.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/File GetAttributes/VB/file getattributes.vb" id="Snippet1":::
]]>
@@ -5772,6 +5808,7 @@ It is not possible to change the compression status of a o
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/File SetLastAccess/CPP/file setlastaccess.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/SetLastAccessTime/file setlastaccess.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/SetLastAccessTime/file setlastaccess.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/File SetLastAccess/VB/file setlastaccess.vb" id="Snippet1":::
]]>
@@ -6009,6 +6046,7 @@ It is not possible to change the compression status of a o
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/File SetLastWrite/CPP/file setlastwrite.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System.IO/File/SetLastWriteTime/file setlastwrite.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/SetLastWriteTime/file setlastwrite.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/File SetLastWrite/VB/file setlastwrite.vb" id="Snippet1":::
]]>
@@ -6442,6 +6480,7 @@ It is not possible to change the compression status of a o
The following example writes selected lines from a sample data file to a file.
:::code language="csharp" source="~/snippets/csharp/System.IO/File/AppendAllLines/program.cs" id="Snippet1":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/AppendAllLines/program.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.io.file.writeallappendall/vb/program.vb" id="Snippet1":::
]]>
@@ -6541,6 +6580,7 @@ It is not possible to change the compression status of a o
The following code example demonstrates the use of the method to write text to a file. In this example a file is created, if it doesn't already exist, and text is added to it.
:::code language="csharp" source="~/snippets/csharp/System.IO/File/ReadAllLines/AllText.cs" id="Snippet00":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/ReadAllLines/AllText.fs" id="Snippet00":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IO.File.AllLines/vb/AllText.vb" id="Snippet00":::
]]>
@@ -6734,6 +6774,7 @@ It is not possible to change the compression status of a o
The following code example demonstrates the use of the method to write text to a file. In this example a file is created, if it doesn't already exist, and text is added to it.
:::code language="csharp" source="~/snippets/csharp/System.IO/File/ReadAllLines/AllText_Encoding.cs" id="Snippet00":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/ReadAllLines/AllText_Encoding.fs" id="Snippet00":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IO.File.AllLines_Encoding/vb/AllText_Encoding.vb" id="Snippet00":::
]]>
@@ -6932,6 +6973,7 @@ It is not possible to change the compression status of a o
The following code example demonstrates the use of the method to write text to a file. In this example a file is created, if it doesn't already exist, and text is added to it.
:::code language="csharp" source="~/snippets/csharp/System.IO/File/AppendAllText/AllText.cs" id="Snippet00":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/AppendAllText/AllText.fs" id="Snippet00":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IO.File.AllText/vb/AllText.vb" id="Snippet00":::
]]>
@@ -7031,6 +7073,7 @@ It is not possible to change the compression status of a o
The following code example demonstrates the use of the method to write text to a file. In this example a file is created, if it doesn't already exist, and text is added to it.
:::code language="csharp" source="~/snippets/csharp/System.IO/File/AppendAllText/AllText1.cs" id="Snippet00":::
+ :::code language="fsharp" source="~/snippets/fsharp/System.IO/File/AppendAllText/AllText1.fs" id="Snippet00":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IO.File.AllText_Encoding/vb/AllText.vb" id="Snippet00":::
]]>