#Csharp


Posts From The Archive

XML Comment Outlining In Visual Studio 2015 'Fixed'

Introducing SquishyVS

When I look at a class file, I will frequently collapse it down to its method signatures. Maybe I want to scan the file for a particular method. Maybe I want to get an overview of what functionality the class contains. Could be any number of reasons. Ultimately it’s a quick way to minimize the noise and isolate what I really want to see. In a C# class file, the noisiest bits - easily - are the XML comments that decorate everything from the class itself to all its containing methods and properties. [Read More]

Unit Testing HostingEnvironment.MapPath()

Without getting into all the whys and wtfs, the other day I had a need to dynamically render and inject html snippets into various webpages at runtime. The project I’m working on originally created the html in C# by concatenating string fragments and formatting them with runtime values. With all the requisite escape sequences needed to create valid html (including encapsulated JavaScript), this approach struck me as a bit messy and I decided to take a different route. [Read More]

Get Rendered LocalReport Values with OpenXml

How oh how is one to get XML from a local (not server) SSRS report? As it turns out, via Excel. The LocalReport.Render() method only supports Excel, PDF, and Image formats, but since the Excel 2007+ file format is just compressed XML, it didn’t take too much finagling to get what I was really after. The only thing I needed was the Microsoft OpenXml SDK, easily acquired through nuget. This code snippet shows how to get the rendered values from a LocalReport in memory: [Read More]

C# File Rename

I don't have a direct need for this little class anymore, but I hate to delete it. Seems like something that would come in handy at some point in the future. [Read More]

C# UNC Path

For some odd reason, System.IO doesn’t include a method to get the UNC path for a file or directory. Even stranger, many code samples resort to using p/invoke in order to get that information. But then I came across this StackOverflow answer that explained a pure .NET way to do the same thing. I gave the original code a good refactoring and turned it into the extension method below. While the most obvious place to stick something like this is the Path class, since it’s static that’s not possible. [Read More]