Solved

Maximum number of files open in C#

Posted on 2013-01-25
7
271 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get String split 5 46
how to truncate multiple tables from SQL Server Database using Stored procedure 8 47
ADO.NET ENTITY DATA MODEL 3 30
Turn on intranet settings 1 35
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…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

947 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

17 Experts available now in Live!

Get 1:1 Help Now