[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.7

How to Write StringBuilder to File.

Asked by rkulp in Microsoft Visual Basic.Net, Microsoft Visual C#.Net, .NET

Tags: VB 2005, Message="The process cannot access the file 'C:\Stat Audits\ABC Aircraft Fabricators\ABCAccruals\ABC Accruals.SXML' because it is being used by another process."

I am trying to resolve an issue with desearializing a SOAP XML file in a program that did not build it. I can do it by reading in the XML file into a StreamBuilder object and using replace to change the assembly. However when I try to save the new file I get the "The process cannot access . . . " error regardless of the file name that I use. I even checked for existence of the file and deleted it, if necessary. I would think the deletion would fail if the file were actually in use by another process. So, I'm stuck. I can't get an answer to my other posting ( http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_23713862.html ) and can't get the work around to write. The code is attached as well as the error details.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
*************Code********************
        Private Sub FixTXML(ByVal FileName As String)
            Dim fs As FileStream = New FileStream(FileName, FileMode.Open, FileAccess.Read)
            Dim sr As New StreamReader(fs)
            Dim allText As String = sr.ReadToEnd
            Dim sb As StringBuilder = New StringBuilder(allText)
            fs.Close()
            fs = Nothing
            sb.Replace("TSEPWin/TSEPWin5", "TSEPWinSim/TSEPWinSim")
            Dim NewFileName As String = FileName.Replace(".TXML", ".SXML")
            If My.Computer.FileSystem.FileExists(NewFileName) Then My.Computer.FileSystem.DeleteFile(NewFileName)
            Dim fs2 As FileStream = New FileStream(NewFileName, FileMode.OpenOrCreate)
            Dim sw As StreamWriter = New StreamWriter(NewFileName, False)
            sw.Write(sb.ToString)
            sw.Close()
            fs2.Close()
            sw = Nothing
            fs2 = Nothing
        End Sub
 
************Error Details*****************
System.IO.IOException was unhandled
  Message="The process cannot access the file 'C:\Stat Audits\ABC Aircraft Fabricators\ABCAccruals\ABC Accruals.SXML' because it is being used by another process."
  Source="mscorlib"
  StackTrace:
       at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
       at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
       at System.IO.StreamWriter.CreateFile(String path, Boolean append)
       at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
       at System.IO.StreamWriter..ctor(String path, Boolean append)
       at TSEPWin.My.MyApplication.FixTXML(String FileName) in E:\TSEPWin\TSEPWin.NET\ApplicationEvents.vb:line 89
       at TSEPWin.My.MyApplication.MyApplication_Shutdown(Object sender, EventArgs e) in E:\TSEPWin\TSEPWin.NET\ApplicationEvents.vb:line 69
       at Microsoft.VisualBasic.ApplicationServices.ShutdownEventHandler.Invoke(Object sender, EventArgs e)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnShutdown()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at TSEPWin.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
[+][-]09/10/08 12:14 PM, ID: 22441854Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/10/08 12:23 PM, ID: 22441950Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/10/08 12:26 PM, ID: 22441994Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/10/08 12:27 PM, ID: 22442011Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/10/08 12:34 PM, ID: 22442072Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/10/08 12:42 PM, ID: 22442154Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Microsoft Visual Basic.Net, Microsoft Visual C#.Net, .NET
Tags: VB 2005, Message="The process cannot access the file 'C:\Stat Audits\ABC Aircraft Fabricators\ABCAccruals\ABC Accruals.SXML' because it is being used by another process."
Sign Up Now!
Solution Provided By: VBRocks
Participating Experts: 1
Solution Grade: A
 
[+][-]09/10/08 12:45 PM, ID: 22442198Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/10/08 12:55 PM, ID: 22442300Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/10/08 01:59 PM, ID: 22442969Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/10/08 02:17 PM, ID: 22443153Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 / EE_QW_2_20070628