Hi Everyone,
I'm sure this is a beginner's error but I cannot figure it out. I
keep getting the following error:
The process cannot access the file 'C:\Users\Public\Documents\Cerf Pen
App\DesktopApps\cs\GetPenInformation\bin\x86\Debug\cerf-servers.txt'
because it is being used by another process.
Here is my code:
File.Create(UserCerfServerListFileLocation);
using (StreamWriter sw = new
StreamWriter(UserCerfServerListFileLocation, true))
{
foreach (KeyValuePair<string, CerfServer> pair in
servers)
{
sw.WriteLine(pair.Value.toCommaSeparatedString());
}
}
Any help is greatly appreciated. Thank you.
Exception Detail:
System.IO.IOException was unhandled
Message=The process cannot access the file 'C:\Users\Public\Documents
\Cerf Pen App\DesktopApps\cs\GetPenInformation\bin\x86\Debug\cerf-
servers.txt' 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, Boolean useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode,
FileAccess access, FileShare share, Int32 bufferSize, FileOptions
options)
at System.IO.StreamReader..ctor(String path, Encoding encoding,
Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)
at System.IO.StreamReader..ctor(String path)
at GetPenInformation.CerfServerList.Pull() in C:\Users\Public
\Documents\Cerf Pen App\DesktopApps\cs\GetPenInformation
\CerfServerList.cs:line 105
at GetPenInformation.CerfServerList..ctor(String serverName,
String serverAddress, String serverPort, String useProxy) in C:\Users
\Public\Documents\Cerf Pen App\DesktopApps\cs\GetPenInformation
\CerfServerList.cs:line 42
at GetPenInformation.AddCerfServerForm.button2_Click(Object
sender, EventArgs e) in C:\Users\Public\Documents\Cerf Pen App
\DesktopApps\cs\GetPenInformation\AddCerfServer.cs:line 28
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m,
MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at
System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at GetPenInformation.Controller.Run() in C:\Users\Public
\Documents\Cerf Pen App\DesktopApps\cs\GetPenInformation
\Controller.cs:line 33
at GetPenInformation.GPI.Main() in C:\Users\Public\Documents
\Cerf Pen App\DesktopApps\cs\GetPenInformation
\GetPenInformation.cs:line 25
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,
String[] args)
at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly,
String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean
checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at
System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext
activationContext, String[] activationCustomData)
at
System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext
activationContext)
at System.Activator.CreateInstance(ActivationContext
activationContext)
at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
--
You received this message because you are subscribed to the Google
Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
Web Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
or visit the group website at http://megasolutions.net