c# - What am not disposing while creating a iCal file? -


In the context of my question

I am using this code to create an iCal file But I'm not sure whether I am correcting it or getting this error as something needed for disposal,

  System.IO.IOException: can not access the process file ' C: \ doc.ics' because it is being processed by another System.IO.__ Error.WinIOError (Int32 errorCode, string maybeFullPath) on System.IO.FileStream.Init (string path, F ileMode mode, using FileAccess, Int32 rights, Boolean useRights, fileshare share, Int32 BufferSize, FileOptions options, secAttrs SECURITY_ATTRIBUTES, string msgPath, Boolean bFromProxy) on System.IO.FileStream..ctor (string path, System.IO.StreamWriter .CreateFile (String Path, FileMode Mode on Boolean Attached, FileAccess Use, FileShare Share, Int32 BufferSize, FileOptions Options) System.IO.StreamWriter..ctor at System.IO.StreamWriter..ctor (String Path, Boolean Attached, Encoding encoding, int32 bufferSize) (string path)  on  

code I am using. ,

  string filePath = paramUri.LocalPath.ToString () TrimStart ("filePath: ///" .ToCharArray ()); Int lastSlash = filePath.LastIndexOf ('\\'); If (last slash & gt; 0) {string folder path = file path Asbestring (0, last slash); DirectoryInfo di = new directoryinfo (folderpath); If (! Di.Exists) di.Create (); } // location using the specified URI (StreamWriter sw = new StreamWriter (filepath)) {// enable Autoflush we do not have to worry about closing StreamWriter sw.AutoFlush = true to create a file Use a StreamWriter; Sw.WriteLine ("BEGIN: VCALENDAR"); Sw.WriteLine ("PRODID: - // Microsoft Corporation // Outlook 12.0 MIMEDIR // EN"); Sw.WriteLine ("version: 2.0"); Sw.WriteLine ("method: published"); Sw.WriteLine ("X-MS-OLK-FORCEINSPECTOROPEN: correct"); // I added more details, but they are not relevant to the post}    

as error StreamWriter is the constructor, the file is not locked by the code include.

I think it has been locked by another process, perhaps you have opened it in a text editor?

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -