Home > Net >  How to close the FileStrem?
How to close the FileStrem?

Time:10-22

Public void UtoPdf (string Repid)
{
FileStream FST=new FileStream (PdfFile, FileMode. Open, FileAccess. Read, FileShare. ReadWrite);
This. PdfViewer1. LoadDocument (FST);
//control read PDF file here
}



Private void gridView1_FocusedRowChanged (object sender, DevExpress XtraGrid. Views. The Base. The FocusedRowChangedEventArgs e)
{
//how to how to close the file stream above here??

}

CodePudding user response:

Process has been occupied

CodePudding user response:

Using (FileStream FST=new FileStream (PdfFile, FileMode. Open, FileAccess. Read, FileShare. ReadWrite))
{
This. PdfViewer1. LoadDocument (FST);
}

IO operations where with clearance is better

CodePudding user response:

You new FileStream, in a function is a local variable, the scope for the current function only, not directly referenced in another function, file streams can be variable according to the parameter passed to another function, or file stream is defined as public visible, the following example is defined file stream outside the function, so these two functions you can use this variable,

FileStream FST=null;
Public void UtoPdf (string Repid)
{
FST=new FileStream (PdfFile, FileMode. Open, FileAccess. Read, FileShare. ReadWrite);
This. PdfViewer1. LoadDocument (FST);
//control read PDF file here
}

Private void gridView1_FocusedRowChanged (object sender, DevExpress XtraGrid. Views. The Base. The FocusedRowChangedEventArgs e)
{
//how to how to close the file stream above here??
FST. Close ();
}

CodePudding user response:

1. FST. Close ();

2. Using (FileStream FST=new FileStream (PdfFile, FileMode. Open, FileAccess. Read, FileShare. ReadWrite))
{
.
}

CodePudding user response:

Using fine
  •  Tags:  
  • C#
  • Related