Link to home
Start Free TrialLog in
Avatar of JDL129
JDL129

asked on

Maximum number of files open in C#

Hey guys!!

We have an application that downloads PDF's and xml files from the clouds, opens them, prints them, but apparently is unable to close them.  I need someone to help me with C# code to tell me how to programmatically close these files after they are printed.

Thanks!!

Jerry
Avatar of Element1910
Element1910
Flag of United States of America image

Can you provide some source code? Like, how are they being opened and printed or what source code have you attempted to close the files?
If you are simply using a FileStream you can try this after the printing operation completes, assuming your FileStream object is called "fileStream", you can simply call the close() method on the object like so:
fileStream.Close();

Open in new window

Avatar of JDL129
JDL129

ASKER

Element1910!!!  Thanks for the post!!

This is some of the code:

writeLog("Get SentTime.");
                ft = iTextSharp.text.FontFactory.GetFont(iTextSharp.text.FontFactory.HELVETICA, 8, iTextSharp.text.Font.BOLD);
                string strMsgSent = "";
                pdfDocPatient = pdfDoc.GetElementsByTagName("SentTime");
                if (pdfDocPatient.Count > 0)
                {
                    strMsgSent = "\r\nSent:" + InitVar.getNullString(emtNum - 12) + pdfDocPatient[0].InnerText;
                }
                pdfDocPatient = pdfDoc.GetElementsByTagName("MessageID");
                if (pdfDocPatient.Count > 0)
                {
                    strMsgSent = strMsgSent + "  Sender Message Id:" + pdfDocPatient[0].InnerText;
                }
                writeLog("Get StoreName.");
                pdfDocument.Add(new iTextSharp.text.Paragraph(strMsgSent, ft));
                pdfDocPatient = pdfDoc.GetElementsByTagName("StoreName");
                if (pdfDocPatient.Count > 0)
                {
                    pdfDocument.Add(new iTextSharp.text.Paragraph("To:" + InitVar.getNullString(emtNum - 9) + pdfDocPatient[0].InnerText, ft));
                }

                pdfDocPatient = pdfDoc.GetElementsByTagName("Pharmacy");
                if (pdfDocPatient.Count > 0)
                {
                    pdfDocument.Add(new iTextSharp.text.Paragraph(InitVar.getNullString(emtNum - 4) + pdfDocPatient[0]["Address"]["AddressLine1"].InnerText, ft));
                    pdfDocument.Add(new iTextSharp.text.Paragraph(InitVar.getNullString(emtNum - 4) + pdfDocPatient[0]["Address"]["City"].InnerText + " " + pdfDocPatient[0]["Address"]["State"].InnerText, ft));
                    pdfDocument.Add(new iTextSharp.text.Paragraph(InitVar.getNullString(emtNum - 4) + pdfDocPatient[0]["Address"]["ZipCode"].InnerText, ft));
                }


                writeLog("Get Pharmacy.");
                XmlNodeList pdfDocNodeList = pdfDoc.GetElementsByTagName("Pharmacy");
                if (pdfDocNodeList.Count > 0)
                {

                    foreach (XmlNode node in pdfDocNodeList[0])
                    {
                        if (countNub > 0)
                        {
                        }
                        countNub++;
                    }
                }

                pdfDocument.Close();

                if (chkPrint.Checked == true && txtPrinter.Text.Trim() != string.Empty)
                {


                    PrintDoc(pdfName);

                    pdfDocument = null;

Any ideas?

Thanks again,

Jerry
Avatar of angus_young_acdc
From work I've done with PDF documents the Adobe process didn't always stop after a close, so that could be the reason if you check TaskManager.  I tried to dispose of the calls to Adobe but in the end I had to do a search for all running processes and kill Adobe.
Avatar of JDL129

ASKER

angus_young_acdc!!!!  Thanks for the post!!!

Could you please post some code here as to how to do that?  You would be my hero!!!

Thanks,
Jerry
ASKER CERTIFIED SOLUTION
Avatar of angus_young_acdc
angus_young_acdc
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JDL129

ASKER

You're a life saver!!!!!!!

Thanks again,

Jerry