Tag Archives: c#

How to open a new tab in an existing Internet Explorer instance in C#

A problem that I recently came across is when opening a new Internet Explorer instance in C# the user was being required to login to a site that they had already logged in to. It was pretty clear that this was because the existing session was not being used as a new IE process was being started, therefore I surmised that the solution was to utilise the existing process.

I had read previously about the Navigate2 API and thought it may help but it wasn’t entirely clear how to use it and specifically how to use it on an existing IE instance, so I feel this blog may help others.

Continue reading How to open a new tab in an existing Internet Explorer instance in C#

How to save to PDF in C# using Word 2003 or 2007 without SP 2 (using Pechkin)

I’ve spent a significant amount of time lately on trying to solve this issue and came across many, many barriers, so I thought I’d share with you my findings and the solution that I used. Whilst Word 2007 SP2 (or Word 2007 using the Save As PDF Add-in) and above natively support saving documents as PDF (and can therefore be used by C# to save as if saving a normal .doc or .docx – you can do this easily by adapting my code) below this level it is not possible. There are a few different ways that this problem can be solved (notably, using a paid library or a web service) but most involve payment and some involve methods that, in my case, were not acceptable (e.g. having to install additional software or having to access locations that were locked down).

Continue reading How to save to PDF in C# using Word 2003 or 2007 without SP 2 (using Pechkin)

How to force open Internet Explorer 32-bit or 64-bit in C#

On a project I was recently working on it was necessary to open a URL in Internet Explorer (a requirement of it to work correctly, unfortunately) and we had a few “bugs” which seemed to randomly occurred. It turned out this was due to Process.Start(“iexplore.exe”) loading 32-bit IE whereas it seems we required 64-bit.

Continue reading How to force open Internet Explorer 32-bit or 64-bit in C#

How to remove warning: The ‘log4net’ element is not declared

So I’ve seen a lot of questions around this issue with generally the only resolution being: “It’s a warning, just ignore this”. Whilst it is safe to do this, for pedants like me there is a true resolution. There are a few places around the net to get this but (like a lot of issues I blog about) you often need to combine the advice. Here’s the true resolution:

Continue reading How to remove warning: The ‘log4net’ element is not declared

Colour your Log4Net events in your RichTextBox

You’re most probably here because you have already read my article How to watch your log through your application in Log4Net and you’re thinking “that’s great, but I need to somehow differentiate all of this output!” – either that or you just really need a handy way to format certain keywords within your RichTextBox.

Continue reading Colour your Log4Net events in your RichTextBox

Scrolling textbox when text is added, but not if the user has scrolled

You may (or may not) have read my recent article How to watch your log through your application in Log4Net which allows you to append Log4Net events direct in to a textbox – if so, you may then also have come across a frustration that I also had, which is that whenever the texbox is updated it scrolls incorrectly and what you actually want is for it to scroll to the bottom unless the user has scrolled themselves and therefore it should remain in place (so that the user can carry on reading where they are).

Continue reading Scrolling textbox when text is added, but not if the user has scrolled

How to watch your log through your application in Log4Net

Log4Net is an excellent logging system that allows you to clearly see what your application is doing and when, making it very easy to debug your app during development but especially during production. I have previously demonstrated how to use Log4Net in C# which enables you to log output to your console for the former and to a file for the latter, but recently I had a requirement to also log to screen during production. This is how I achieved it:

Continue reading How to watch your log through your application in Log4Net

How to access WebAPI from a .Net 3.5 client in C#

So, like me, you may have come across some incompatibility within your WebAPI client that means you can’t use .Net 4/4.5 (which is required to use HttpClient and HttpResponseMessage etc.) – or you’re writing a web service to fill in due to this incompatibility. This solution should allow you to access your API (using POST) from .Net 3.5 (and above, maybe even below).

Continue reading How to access WebAPI from a .Net 3.5 client in C#

Installing your C# project in Visual Studio 2012 (or earlier)

So you may or may not be aware that Visual Studio 2012 no longer has a built in project that will install your application for you – I can understand why this is, as it allows third parties to develop these and lets them focus on improving the programming experience, but I can also understand that this change has frustrated and confused developers (like myself). So I thought I’d share a guide as to how you can create an installer for your Visual Studio 2012 project (NOTE this also works in older versions).

Continue reading Installing your C# project in Visual Studio 2012 (or earlier)