Saturday, February 14, 2015

Powershell to add Read permission on all files in a directory

Recently I needed to update all the files in a specific directory, adding Read permission for the "Users" NTFS group.  Here is a Powershell script to do that.  It can be easily modified to update other users/groups or different permission sets.

$base = "C:\somefolder"
$files = get-childitem $base
foreach ($file in $files) {
    $Acl = Get-Acl $file.FullName
    $Ar = New-Object  system.security.accesscontrol.filesystemaccessrule("Users","Read","Allow")
    $Acl.SetAccessRule($Ar)
    Set-Acl $file.FullName $Acl
}

Wednesday, February 4, 2015

Basic rules for using ResolveClientUrl in master pages (ASP.NET)

When writing ASP.NET Web Forms, the basic rules for using ResolveClientUrl in master pages are:
<img src="<%= ResolveClientUrl("~/x/resource.jpg")%>" />
<script src="<%= ResolveClientUrl("~/x/resource.js")%>"></script>
If you want to use ResolveClientUrl in the master page <head> section for script tags:
<asp:PlaceHolder ID="PlaceHolder1" runat="server">
   <script src="<%= ResolveClientUrl("~/x/resource.js")%>"></script>
</asp:PlaceHolder>

You do not need to use ResolveClientUrl for CSS link elements in the <head> section (they will automatically be resolved by ASP.NET).

Friday, January 23, 2015

PowerShell: Get a unique list of file name extensions within a directory folder (and sub-folders)

Here is a basic PowerShell script that will provide you a nice list of unique file name extensions for a given directory path. Nothing fancy here, but comes in handle once and a while.

Notice the -Recurse parameter that will drill down every sub-directory as well; remove this if you only want the top level directory.

Get-ChildItem -Path C:\Scripts -Recurse | Select-Object Extension | Sort-Object Extension | Get-Unique -asString

Woo-hoo!

Saturday, October 25, 2014

Microsoft OWIN: Getting base path for web services (C#)

In my recent post on using OWIN and WebApi, I described how to separate your controllers into a separate DLL. Often the controllers need to call other methods that may need access to the base path of the web service (e.g. the bin folder).

The code below can be used to find that base path from other classes, without having to always pass a path parameter from method to method.

Thursday, October 23, 2014

OWIN hosting using a Separate WebApi Controller DLL

Here is a bare bones demonstration (4 minutes) showing you how to create a standalone class library of a WebApi controller, then hosting the controller in Microsoft's OWIN (in IIS). This is done using Visual Studio 2013 Update 3.

The video can be watched here: YouTube Watch

The source can be downloaded here: Download Source

What do you think?

Sunday, October 12, 2014

WeightedRandom - Select content based on weights (C# / .NET)

Need to select content from a collection based on weights?  Here is a great .NET 4+ class that is very helpful.

The class can be used with just about any collection and you can pass in a delegate/lamda to determine what the weight is on each collection object.

Tuesday, September 2, 2014

Moving a ClickOnce deployment to another URL/domain

Here is a good video post by Robin on how to move a Microsoft ClickOnce application to another URL (either on the same domain or on a brand new domain).  This process worked very well.

Moving a ClickOnce application (video)

Monday, February 24, 2014

New features in MVC versions (MVC 3 vs. MVC 4 vs. MVC 5)

ASP.NET MVC 3
  • New Project Templates having support for HTML 5 and CSS 3.
  • Improved Model validation.
  • Razor View Engine introduced with a bundle of new features.
  • Having support for Multiple View Engines i.e. Web Forms view engine, Razor or open source.
  • Controller improvements like ViewBag property and ActionResults Types etc.
  • Unobtrusive JavaScript approach.
  • Improved Dependency Injection with new IDependencyResolver.
  • Partial page output caching.

ASP.NET MVC 4
  • ASP.NET Web API, a framework that simplifies the creation of HTTP services and serving a wide range of clients.
  • Adaptive rendering and other look-n-feel improvements to Default Project Templates.
  • A truly Empty Project Template.
  • Based on jQuery Mobile, new Mobile Project Template introduced.
  • Support for adding controller to other project folders also.
  • Task Support for Asynchronous Controllers.
  • Controlling Bundling and Minification through web.config.
  • Support for OAuth and OpenID logins using DotNetOpenAuth library.
  • Support for Windows Azure SDK 1.6 and new releases.

ASP.NET MVC 5
  • Bootstrap replaced the default MVC template.
  • ASP.NET Identity for authentication and identity management.
  • Authentication Filters for authenticating user by custom or third-party authentication provider.
  • With the help of Filter overrides, we can now override filters on a method or controller.
  • Attribute Routing is now integrated into MVC 5.

Source: http://www.webdevelopmenthelp.net/2014/02/ASP.NET-MVC3-Vs-MVC4-Vs-MVC5.html

Sunday, February 23, 2014

ASP.NET: Web Forms vs. MVC (how to decide)

Why ASP.NET Web Forms and Why ASP.NET MVC?

Each can be the “best choice” for a particular solution depending on the requirements of the application and the background of the team members involved. What to choose and when has more to do with business prospective than which one is better than other. When facing a decision to choose between ASP.NET Web Forms or ASP.NET MVC it is important to know that neither technology is meant to replace the other.

Two important factors you should consider while making the choice is:
  1. Rapid application development - If you want to develop anything rapidly ASP.NET Web Forms is the only chance you are having, you can’t even consider for ASP.NET MVC for RAD. (Reasons for RAD may be anything like client is not paying too much, or application is going to be used for only one or two months and won’t require much maintenance.)
  2. Unit Testing - If automatic unit testing is most important factor for you MVC will be best for you.
Other than these, what you can do is, write down all your project requirement and try to compare them with Pros and Cons of both Web Forms and MVC and if possible try to ask yourself following questions and point MVC and Web Forms accordingly
  1. Does your team have good experience with Web Forms or Windows Forms? Well, if yes then probably learning ASP.NET MVC is going to be a tedious task for team, because developers have been used to with ViewState and event driven programming by now and migration is going to be a difficult task.1 point to Web Forms.
  2. Does your team have good experience with ASP.NET MVC? If yes ASP.NET MVC get 1 point
  3. Does your team have experience on ASP or non-Microsoft technologies such as android, ios, JSP, ROR, PHP? If you have been JSP or ASP developer prior then you might be familiar with HTTP get and Post and even u might have hands on with MVC because most of them use MVC by default. It gives 1 point to ASP.NET MVC.
  4. Is JavaScript going to be used extensively? If Yes, MVC gets the point because you get complete control over HTML. 1 point ASP.NET MVC.
  5. Looking for good performance? With no support for ViewState ASP.NET MVC provides good performance gain over traditional ASP.NET Web Forms.1 point ASP.NET MVC.
  6. Planning to reuse the same input logic? If yes stick with MVC.
Source: http://www.codeproject.com/Articles/528117/WebForms-vs-MVC

Monday, December 23, 2013

Tortoise SVN Settings for Beyond Compare 4

I recently rebuilt my computer and had to re-enter my Tortoise SVN settings for Beyond Compare. Now I won't forget!

Diff Viewer
"C:\Program Files (x86)\Beyond Compare 4\BComp.exe" %base %mine /title1=%bname /title2=%yname /leftreadonly

Merge Tool
"C:\Program Files (x86)\Beyond Compare 4\BComp.exe" %mine %theirs %base %merged /title1=%yname /title2=%tname /title3=%bname /title4=%mname

Tuesday, October 15, 2013

Compress all JPG/JPEG files in a directory tree (simple console application)

I needed a quick application to increase the compression of all .jpg files in a directory tree. This application is a console program that takes three command-line parameters:
compressjpg inDir outDir compressionLevel extensions
compressLevel is a number from 0 to 100, where 0 is maximum compression and 100 is no compression. extensions is a comma/semi-colon delimited list of file extensions to process. For example:
C:> compressjpg c:\myfiles c:\newfiles 80 jpg;jpeg
Download the Visual Studio 2012, .NET 4.5 solution (source code) by clicking here.

Can't RDP? How to enable / disable virtual machine firewall for Azure VM

Oh no!  I accidentally blocked the RDP port on an Azure virtual machine which resulted in not being able to log into the VM anymore.  I did ...