filestream - The process cannot access the file it is being used by another process c# -


i using savefiledialog save pdf file.but @ creation of pdf file getting error.

the process cannot access file being used process c# 

here code in c#..

savefiledialog savefiledialog1 = new savefiledialog();  savefiledialog1.filter = "pdf files (*.pdf)|*.pdf|all files (*.*)|*.*"; savefiledialog1.filterindex = 0; savefiledialog1.restoredirectory = true;  if (savefiledialog1.showdialog() == dialogresult.ok) {     if ((mystream = savefiledialog1.openfile()) != null)     {         // code write stream goes here.         pdfwriter.getinstance(pdfdoc, mystream);         //mystream.close();         using (filestream file = new filestream(savefiledialog1.filename, filemode.create, system.io.fileaccess.write, fileshare.readwrite))         {             byte[] bytes = new byte[mystream.length];             mystream.read(bytes, 0, (int)mystream.length);             file.write(bytes, 0, bytes.length);             mystream.close();         }     } 

i getting error @ line..

using (filestream file = new filestream(savefiledialog1.filename, filemode.create, system.io.fileaccess.write, fileshare.readwrite)) 

here pdf file code

        stream mystream;          document pdfdoc = new document(pagesize.a4, 10f, 10f, 10f, 0f);          using (memorystream stream = new memorystream())         {             pdfdoc.open();             piechart.saveimage(stream, chartimageformat.png);             itextsharp.text.image chartimage = itextsharp.text.image.getinstance(stream.getbuffer());             chartimage.scalepercent(75f);             pdfdoc.add(chartimage);         }         pdfdoc.close(); 

please me. in advance.

you writig same file reading from. hence error message.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -