Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 12, 2025

The Visual Basic documentation for reading text files contained hardcoded absolute file paths (like "C:\test.txt") that cause issues on different systems and don't follow best practices. Additionally, users were requesting examples showing how to load text files into RichTextBox controls, which wasn't covered.

Changes Made

Fixed hardcoded file paths:

  • Changed "C:\test.txt" to "test.txt" in existing code snippets to use relative paths
  • This prevents issues with drive letters and path separators on different operating systems

Added RichTextBox integration examples:

  • New snippet showing basic file-to-RichTextBox loading pattern
  • Advanced snippet with proper error handling and Path.Combine for robust path construction

Enhanced documentation:

  • Added new section "To read from a text file into a RichTextBox control"
  • Included warning note about avoiding hardcoded absolute paths
  • Provided guidance on using Path.Combine for cross-platform compatibility

Added project file for CI build:

  • Created VbFileIORead.vbproj targeting .NET Framework 4.8 to enable proper CI builds
  • Project builds successfully as a Library project

Example of the improvement:

Before:

fileReader = My.Computer.FileSystem.ReadAllText("C:\test.txt")

After:

fileReader = My.Computer.FileSystem.ReadAllText("test.txt")
' Or with proper path handling:
Dim filePath As String = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "test.txt")
fileReader = My.Computer.FileSystem.ReadAllText(filePath)

These changes address user frustrations with compilation errors and provide the RichTextBox functionality specifically requested in the issue.

Fixes #33919.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


Internal previews

📄 File 🔗 Preview link
docs/visual-basic/developing-apps/programming/drives-directories-files/how-to-read-from-text-files.md How to: Read From Text Files in Visual Basic

@dotnet-policy-service dotnet-policy-service bot added the okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. label Sep 12, 2025
@Copilot Copilot AI changed the title [WIP] File Reader code snippet violates "the rules" for presented on the same page Fix Visual Basic file reading examples: remove hardcoded paths and add RichTextBox support Sep 12, 2025
@Copilot Copilot AI requested a review from BillWagner September 12, 2025 20:06
Copilot finished work on behalf of BillWagner September 12, 2025 20:06
@BillWagner
Copy link
Member

@copilot Can you adda vbproj file to this folder for the CI build.

Copy link
Contributor Author

Copilot AI commented Sep 15, 2025

@copilot Can you adda vbproj file to this folder for the CI build.

Added VbFileIORead.vbproj file targeting .NET Framework 4.8. The project builds successfully as a Library project (commit 5e362d7).

@Copilot Copilot AI changed the title Fix Visual Basic file reading examples: remove hardcoded paths and add RichTextBox support Fix Visual Basic file reading examples: remove hardcoded paths, add RichTextBox support, and include project file Sep 15, 2025
Copilot finished work on behalf of BillWagner September 15, 2025 15:01
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ready for final review.

@BillWagner BillWagner marked this pull request as ready for review September 15, 2025 18:33
@BillWagner BillWagner requested a review from a team as a code owner September 15, 2025 18:33
…/VB/VbFileIORead.vbproj

Co-authored-by: Genevieve Warren <[email protected]>
@BillWagner BillWagner enabled auto-merge (squash) September 17, 2025 17:08
@BillWagner BillWagner disabled auto-merge September 17, 2025 17:15
@BillWagner BillWagner merged commit 0fdcc8c into main Sep 17, 2025
9 of 10 checks passed
@BillWagner BillWagner deleted the copilot/fix-33919 branch September 17, 2025 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet-visualbasic/svc okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File Reader code snippet violates "the rules" for presented on the same page
3 participants