Feeds:
Posts
Comments

Archive for the ‘C#’ Category

I’ve got a new article up at The Code Project about how the internal keyword in C# can be used safely while preserving encapsulation. In a nutshell, it is about using internal interfaces instead of giving internal access directly to properties or fields, and how this can help maintain strict encapsulation while nevertheless granting special access to service layers. Give it a read and don’t forget to vote!

Advertisements

Read Full Post »

Keywords: Open Office, Ghostscript, Do It Yourself Convert Microsoft Word, Excel, Powerpoint to PDF

I’ve written a small program that uses Open Office to open and save different kinds of Microsoft Office files to PDF, and optionally merge them into a single output PDF file using GPL Ghostscript. I posted the code and article at the Code Project: http://www.codeproject.com/KB/java/PDFCM.aspx.

It’s a command line program, and we’re using a simplified version of it in production to do back-office conversions and merges of office files that we get from filling out forms internally and others that we get from customers. There are potentially many documents, and they can vary in size, so it is very cumbersome to cut, paste, print and scan everything to PDF (which is what our staff were doing when I started this project.)

Fortunately, it turns out that (1) one can use PRNADMIN.DLL with a Postscript Printer driver and an ActiveX IE browser to render a web page to Postscript, (2) Open Office can batch convert Microsoft Office files (and many more) to PDF, and (3) Ghostscript will merge Postscript and PDF on the command line.
(more…)

Read Full Post »

Keywords: .Net, Email, Attachments, Where are all the open file handles coming from?

Sending an Email message in .Net is easy using the System.Net.Mail namespace. Just make sure that if you use attachments, you dispose of them when you’re done. The reason is that creating and adding an attachment from a filename silently opens a file on your system and holds it open either until the attachment is disposed or until the entire message is disposed. The timing of opening/closing the attachment file has nothing to do with when you actually send the message. Given that the garbage collector is usually configured for best response time, that could very well be long after your message has gone out of scope; ie- until your process dies or is bounced by a web server.

(more…)

Read Full Post »

Keywords: Exception Handling in Java, out parameters in C#

I’ve been thinking a lot about error handling lately. And my new mantra is locality, locality, locality.

My day to day programming work is primarily in C#, but it used to be in Java. I still do some work in Java. Last year, I designed and built (with help) a multi-tier web application for internal application form processing. It included an (MVC) presentation layer, a business layer, and a data access layer. Each form contains up to ~400 different kinds of data fields that may or may not be present in each form instance (depending on how it is filled out.)
(more…)

Read Full Post »

Very strange. I have a few interfaces I needed to re-factor. Step 1 was supposed to be simple: rename the interfaces. I highlighted an interface name in Visual Studio, right clicked and selected rename, and waited. And waited.

And waited.

So I think, as a progress bar indicates that every file in my solution is being scanned, “Oh it’s just a first time thing, it’s building an index, right?” So after it was finished I highlighted another interface name, right clicked and selected rename, and waited. And waited.

And waited.

It takes less time to clean and re-compile my solution from scratch than it does to rename one interface, and I have many interfaces to rename. One would think that an index of tokens would be built by the compiler that could be used in a renaming operation.

One would be wrong.

Update: By the way, this is so much faster in SharpDevelop.  My memory is that it was much faster in IntelliJ (for Java) as well.  Hopefully this is fixed in VS2008.

Read Full Post »

Recently I deployed an ASP.Net web application that was designed to gather complex form data and store it in a database. The object model was large and complex enough that it couldn’t be stored in View State, given the network within our organization. So instead we stored the form data in Session state. Simple enough, server memory is comparatively cheap. During 10 months of requirements meetings however, it never came up that users might want to have multiple forms open at the same time, each looking at different instances of the business data. And this week, precisely that happened.

What does that spell? That’s right: M-A-Y-H-E-M.
(more…)

Read Full Post »

Keywords: Excel COM Error, 8008005

As a follow on to my amusing misadventures with Excel COM running server side, I did some more digging and found out more interesting details on this situation. For starters, it’s not supported:KB257757. That doesn’t really bother me so much, it’s stable enough to run a few reports. And I firmly believe that if you’re not getting outside of your safe zone from time to time, then you’re probably not accomplishing very much. (That’s a corollary of Toback’s Law: If you never miss any flights, then you’re spending too much time in airports.)

(more…)

Read Full Post »

Older Posts »