Solved

Maximum number of files open in C#

Posted on 2013-01-25
7
266 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now