can't close file with FileStream

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bAsiiiM
    New Member
    • Feb 2015
    • 1

    #1

    can't close file with FileStream

    Code:
    FileStream obj = new FileStream(System.Convert.ToString(row.Cells["Lec_media"].Value), FileMode.Open, FileAccess.Read, FileShare.Read);
                    
    
     
     if (Startdate2 == JCM_NOW2)
                    {
                        if (checkBox1.Checked == true)
                        {
    
                            try
                            {
    
    
                                obj = null;
                                System.Diagnostics.Process.Start(System.Convert.ToString(row.Cells["Lec_media"].Value));
                               
                            }
                            finally
                            {
                                if (obj != null)
                                obj.Close();
    
                            }
                        }
    
                    }
    
    
                  
                if (Enddate2 == JCM_NOW2)
                {
    
    
    
                    if (obj != null) ((IDisposable)obj).Dispose();
    
                    obj.Close();
    
                   // this code does not close the file which opened above .. why?
                   
    
                }
    Last edited by Rabbit; Feb 11 '15, 07:13 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Consider utilizing the Using Statement. See the link for more information and examples.

    -Frinny

    Comment

    Working...