Solved

Maximum number of files open in C#

Posted on 2013-01-25
7
272 Views
Last Modified: 2013-01-29
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
0
Comment
Question by:JDL129
  • 3
  • 2
  • 2
7 Comments
 
LVL 7

Expert Comment

by:Element1910
ID: 38820156
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?
0
 
LVL 7

Expert Comment

by:Element1910
ID: 38820168
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

0
 

Author Comment

by:JDL129
ID: 38821467
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
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 15

Expert Comment

by:angus_young_acdc
ID: 38826307
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.
0
 

Author Comment

by:JDL129
ID: 38829505
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
0
 
LVL 15

Accepted Solution

by:
angus_young_acdc earned 250 total points
ID: 38831517
Hey Jerry

An example would be:

            foreach (Process process in Process.GetProcesses())
            {
                if (process.ProcessName.Contains("AcroRd")) // process will probably be named differently, open one up and check TaskManager's Processes tab to double check
                {
                    process.Kill();
                }
            }

Open in new window


That will kill every instance of acrobat PDF reader.

I hope this helps
0
 

Author Closing Comment

by:JDL129
ID: 38832045
You're a life saver!!!!!!!

Thanks again,

Jerry
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question