Unlidaamada
New Member
In reference to my question Am I doing it right while reading a file?I am using this code to create a iCal file but not sure if I am doing it right or need to dispose anything as getting this error,\[code\]System.IO.IOException: The process cannot access the file 'C:\doc.ics' because it is being used by another process. 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)\[/code\]Code I am using is,\[code\] String filePath = paramUri.LocalPath.ToString().TrimStart("filePath:///".ToCharArray()); int lastSlash = filePath.LastIndexOf('\\'); if(lastSlash > 0) { String folderPath = filePath.Substring(0, lastSlash); DirectoryInfo di = new DirectoryInfo(folderPath); if(!di.Exists) di.Create(); } //Use a streamwriter to create a file in the location specified in the URI using (StreamWriter sw = new StreamWriter(filePath)) { //Autoflush enabled so we don't have to worry about closing the streamwriter sw.AutoFlush = true; sw.WriteLine("BEGIN:VCALENDAR"); sw.WriteLine("PRODID:-//Microsoft Corporation//Outlook 12.0 MIMEDIR//EN"); sw.WriteLine("VERSION:2.0"); sw.WriteLine("METHODUBLISH"); sw.WriteLine("X-MS-OLK-FORCEINSPECTOROPEN:TRUE"); //I am adding more details but they are not relevant to post }\[/code\]