Skip to main content
I'm streaming on Twitch right now. You should stop by. Let's go!

Tagged: c-sharp

  • ASP.NET/C# image resizer for responsive layouts


    I will probably elaborate on this a bit further when I find some more time, but for now, this post is going to be mostly code. What I have here is a relatively simple way to generate images that are resized server-side based on the screen dimensions (note: not window dimensions) of the web browser requesting them. This way, you're not sending huge images to phones. Pair this with some CSS to scale your images to fit their containers, and you're cooking with gas! …

  • Dynamic GridView rows in ASP.NET


    Here's a simple proof-of-concept for dynamically adding and removing rows in an ASP.NET GridView control while maintaining the existing data. …

  • Validating file uploads in Sitecore WFFM


    Our Sitecore installation was in dire need of a way to lock down file uploads on forms built with the Web Forms for Marketers (WFFM) module; out of the box, it doesn't do any checking at all, which can lead to some risky situations. I tacked on a simple whitelist attribute to the UploadFile control, and our security engineer can breathe easy. …

  • LDAP authentication with C#


    LDAP, or Lightweight Directory Access Protocol, is a convenient, central repository for a system's personnel information. LDAP (and other Active Directory services) are widely-used by organizations big and small to consolidate user credentials and identification data. For instance: a reporting services application, a webmail client, and a database administration suite can all read from the same Directory, with no need for replicating user information. John Doe only has to remember one password for all systems. When he changes it, those changes cascade across the board. …

  • rexCrawler and HelpfulHighlighter are now open source


    After having dipped my toe in the water of open source with some Arachni module changes and the development of a simple WordPress plugin, I've finally taken the plunge; two of my personal projects are now completely open source, and hosted on github. Much of the code is stale—and somewhat embarrassing—but I figured that it was high time I shrug off that self-defensive apprehension and use it as fuel to make me a better developer. …

  • Programmatically compile Audiences in SharePoint 2010


    According to the documentation for the SharePoint 2010 SDK, you cannot trigger Audience compilation programmatically. Well—that's not true. It isn't documented, but it is possible. The painful thing about it is that you must know the ApplicationId of the UserProfileService application. This is where reflection comes in extremely handy! …

  • bulkRename v2.0 released


    I've converted my bulk file renaming utility from VB.NET to C# and made use of a command line arguments parsing library so that it will accept folders and regex patterns with spaces in them. It behaves a bit weird if you don't encapsulate your arguments in quotation marks (") or if you forgo the use of an equals sign (=) between the parameter flag and its argument, but those are small concessions to make. You can download v2.0 to use yourself. …

  • Simple file access concurrency in C#


    When working without the safety net of a RDBMS in a multi-user environment, file concurrency may become an issue. In a project I've been working on recently, XML files are being used as the custom data store. This is all fine and dandy for now—with a user base of 1 (myself)—but when the app is released "into the wild", concurrency may become a serious problem. To remedy this problem (in a simple, no-nonsense fashion), I have been relying on a mutex file to exclude concurrent writes to the XML data store; it has been holding up just fine in my simulated scenarios. The mutex allows for one web request to read in the XML, modify it, and write back to it without being usurped by concurrent requests. There is a fail-safe mechanism which will wait for up to 3 seconds (30 attempts to lock the file) before failing outright. …

  • Check all CheckBoxes in a GridView using jQuery


    If you're working with a GridView control where you've built a CheckBox control into each row of data displayed, odds are, it would be convenient for your users if a "Check/Un-check All" option was available. The following example will show how to do just that; and with only the tiniest bit of jQuery script! …

  • Custom error messages with ValidationSummary in ASP.NET


    Sometimes, there are problems encountered in a code-behind file that don't warrant the extra work and mark-up that would otherwise be required to add CustomValidator controls to the page for displaying error messages to the user through your ValidationSummary. Wouldn't it be nice if you could (somewhat) easily take care of it in your code-behind file alone, without adding additional clutter to your UserControl/Page/etc.? Well, you can! The following IValidator extension class can be added to a Page's Validators list with ease for displaying custom error messages. …

  • Programmatically modifying file permissions in .NET


    For one reason or another, somewhere down the line, you're probably going to want to modify a file's access permissions from your code. Maybe your users have a nasty habit of overwriting them, or you want to ensure that newly-created files are given a specific permission mask. Whatever the reason, the following C# code example shows how to modify a file's access permissions using the System.Security.Principal and System.Security.AccessControl namespaces. …

  • Image dimension Field Validator for Sitecore CMS


    This StandardValidator extension will determine whether or not a given ImageField's source image's height and width match with given parameters. Either parameter can be omitted if, for instance, you only care about validating the width of an image (or conversely, only the height). …

  • Currency Field Validator for Sitecore CMS


    This StandardValidator extension will determine whether or not a given field value passes for currency. In order to do so, it must meet the following requirements: It must pass decimal.TryParse() It must not have more than 2 digits past the decimal point Obviously, this does not fit all international systems—however, in my case, it works for my project (which does not require localization). The code could easily be customized to accommodate additional formats. …

View all tags