Search This Blog

Wednesday, December 16, 2015

Nuget Helpers Package

Uploaded a nuget package containing methods I have been using very often in new projects.

Below is a list of all methods provided at this point:



Nuget install command: Install-Package Helpers

Sunday, December 13, 2015

Enforcing a given number of digits in a numeric value in Javascript

Javascript does not a built-in functionality like C#'s .ToString("0000").

To accomplish the same I came up with the following:

function setNumericFormat(value, numOfDigits, paddingChar) {
var length = value.toString().length;
if (length < numOfDigits) {
var prefix = "";
for (var i = 1; i <= numOfDigits - length; i++) {
prefix += paddingChar;
}
return prefix + value.toString();
}
return value.toString();
}

Resembles a LeftPad function...

Wednesday, November 25, 2015

Need to migrate your sql server database and wondering how will you get all the objects sql scripts ?

Found out that it is quite simple.

In case the link gets broken:

  1. Mouse right-click on the database in question, in the database explorer
  2. Select Tasks
  3. Select Generate Scripts
  4. Choose all the objects you want the scripts to be generated.
That's all.



Thursday, November 12, 2015

Project will not build after adding function or procedure to edmx

Having issues in trying to add a function/procedure to your Entity Data Model - it will not build after that ?
What's more, it works perfectly with Entity Framework version 5 ? And with 6, which you are trying now, does not ?

Well, here's the solution.

Lessons learned: there is such a thing as Entity Framework Tools for Visual Studio, and we need to make sure we have it updated/in sync with the version of Visual Studio we are using in combination with a package we have just downloaded/added to our project.

Dependencies, dependencies, dependencies...

Monday, November 9, 2015

Sunday, November 8, 2015

One more chapter on the topic "Do Not Use Regex to Parse Html"

My bit of contribution to the topic of not using regex to parse html, which comes after I put much effort in doing so :-)

See this question in stackoverflow I just posted.

Thursday, October 8, 2015

A bit about Virtual Paths in ASP.NET applications

In referring to resources such as images in your asp.net application, it is useful to know that a tilde (~) represents the root directory of the application (which you can double-check by taking a look at the framework variable HttpRuntime.AppDomainAppVirtualPath). Using it to reference resource is better since this way is not dependent of location of where the reference is being made.

 For instance, if you are referencing myImage.jpg, which resides in /Content/Images, in a view located at /Views/Partials, if you were to reference the image by its physical path you would need to manually go down to the root folder and then climb up to Content/Images. And if you copy + paste the <img src="..." />  tag where this reference was coded to another view, you might end up with a broken link, since suffices that the source file making the reference be in a different position in the hierarchy for the link to be broken.

You can get over this by having your image tag like <img src="~/Content/Images/myImage.jpg" />. .NET will always translate this path to [contents of HttpRuntime.AppDomainAppVirtualPath]/Content/Images/myImage.jpg. Using the static class VirtualPathUtility, which I just learned about, may also come in handy.

Click here for a good resource on the subject.