Solved

Maximum number of files open in C#

Posted on 2013-01-25
7
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

729 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