sea*_*alz 1 vb.net visual-studio-2010
我有以下内容搜索域并列出每个用户.我正在将它们写入文本文件.问题是每个用户名,因为它被覆盖了另一个用户名.
我需要将它们列在另一个之下.我是否错放了使用声明?
再次感谢你们.
Dim de As New DirectoryEntry()
'Name place to write file to
Dim strFile As String = "C:\MyFile.txt"
Dim fileExists As Boolean = File.Exists(strFile)
'get list of all users on domain and write to file
de.Path = "WinNT://domain.blah.com"
For Each d As DirectoryEntry In de.Children()
Using sw As New StreamWriter(File.Open(strFile, FileMode.OpenOrCreate))
sw.WriteLine(d.Name)
End Using
Next
Run Code Online (Sandbox Code Playgroud)
您StreamWriter
为列表中的每一行打开了一个新内容.尝试交换流编写器和循环的创建:
Using sw As New StreamWriter(File.Open(strFile, FileMode.OpenOrCreate))
For Each d As DirectoryEntry In de.Children()
sw.WriteLine(d.Name)
Next
End Using
Run Code Online (Sandbox Code Playgroud)