troubleshooting Question

VB - ensuring a text file is written to and closed before opening to read from it

Avatar of Beamson
Beamson asked on
Visual Basic.NET
14 Comments1 Solution152 ViewsLast Modified:
I'd like to read the report or text file generated below (3rd from last line) into a textbox:
        Dim config As New MarketplaceWebServiceConfig
        config.ServiceURL = ""
        Dim myClient As New MarketplaceWebServiceClient(AccessKey, SecretKey, ApplicationName, ApplicationVersion, config)
        Dim myRequest As New GetReportRequest
        myRequest.Merchant = SellerID
        myRequest.ReportId = reportId
        myRequest.Report = File.Open("C:\\report\" + reportId.ToString + ".txt", FileMode.OpenOrCreate, FileAccess.ReadWrite)
        Dim myResponse As New GetReportResponse
        myResponse = myClient.GetReport(myRequest)

If I add a final line:
myTextbox.text = File.ReadAllText("C:\\report\" + reportId.ToString + ".txt")
I get "The process cannot access the file "xxx" because it is being used by another process."

What do I need to do to ensure the file is written to and closed before attempting to read from it?
Join our community to see this answer!
Unlock 1 Answer and 14 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros