Getting full path in Windows Service

by Victor 14. July 2014 18:53
AppDomain.CurrentDomain.BaseDirectory

If you need the application path inside of a Windows Service you can use this property to get it. Something I always forget so here it is for easy reference.

Tags: , ,

.NET | C# | Software Development

Excel - Trim all cells

by Victor 31. May 2013 07:52

Here's a macro to trim all selected cells:

 

Sub TrimCells()
    Dim R As Range
    Application.EnableEvents = False
    On Error GoTo ErrH:
    If TypeOf Selection Is Excel.Range Then
        For Each R In Selection.Cells
            If R.HasFormula = False Then
                R.Value = Trim(R.Value)
            End If
        Next R
    End If
ErrH:
    Application.EnableEvents = True
End Sub

Tags: ,

Detecting the File Download Dialog in the Browser

by Victor 11. January 2013 19:22

I ran into a scenario in which I needed to know when a PDF file finished "rendering" to the browser. Actually, it was being served as an attachment. Either way, I needed to know when the client got the response back from the server. This stumped me for a while until I found this extremely useful block post describing a very elegant solution using a cookie. The gist of it is to create a token on the client side and send it to the server with your file request. I did it via the query string. On the server side, when the pdf is done, add a cookie with the value of the token. Back on the client side, poll for a cookie with the token. That's it! Check out the full explanation here.

Tags: ,

javascript | jQuery | Software Development | Web Development

Visual Studio Conditional Pre-Build Event

by Victor 9. January 2013 08:35

Say, for example, you want to execute a pre-build event if the current configuration is not Debug. Then you can do it like so:

 

if not '$(ConfigurationName)' == 'Debug' [YOUR PRE-BUILD STATEMENT]

Sorting with CanJS

by Victor 20. December 2012 18:06

I need to sort a list based on the selected value of a dropdown. I didn't find anything built in in CanJS. The can.Model.List does not have a sort method. Luckily, Curtis created a fiddle that does sorting. I adapted his code a bit and added the dropdown.

 

You can see the jsfiddle here

Tags: , ,

Web Development | javascript

"Invalid column name 'CreatedOn'" - Entity Framework Code First

by Victor 7. September 2012 16:53

I started getting this error in a production system a day ago but nothing had changed in that application. The application is a REST web service and hasn't been touched in months. BUT, I did deploy a different application that uses the same database. The new application uses Entity Framework 5.0 and the existing application uses 4.3. Also, the new application uses Code First Migrations so a new table called __MigrationHistory was automatically added. It turns out that the existing application had automatic migration enabled. So, all I had to do was turn that off using this line of code and redeploy the dll.

 

Database.SetInitializer<MyModelContext>(null);
 
I don't think automatic migrations should be enabled by default but I suppose some people would want it. Sometimes I think MS tries to put too many "automagic" features in their frameworks...

Tags: , ,

Entity Framework | Software Development | Web Development

Entity Framework 5.0!

by Victor 23. August 2012 01:33

Finally, Entity Framework 5.0 is out and it has a whole slew of new cool features. Well, they're cool in the sense that they're finally here but better late than never.

What’s New in EF5

EF 5 includes a number of new features and bug fixes to the EF4.3 release. Most of the new features are only available in applications targeting .NET 4.5, see the Compatibility section for more details.

  • Enum support allows you to have enum properties in your entity classes.
  • Spatial data types can now be exposed in your model using the DbGeography and DbGeometry types.
  • Performance enhancements - these are exciting. Essentially queries will be compiled automatically now. Read more here
  • Code First will now detect if you have LocalDb or SQL Express available for creating new databases. Visual Studio 2012 includes LocalDb, whereas Visual Studio 2010 includes SQL Express.
  • Code First will add tables to existing database if the target database doesn’t contain any of the tables from the model.

The EF Designer in Visual Studio 2012 also has some new features:

  • DbContext code generation for new models means that any new models created using the EF Designer will generate a derived DbContext and POCO classes by default. You can always revert to ObjectContext code generation if needed. Existing models will not automatically change to DbContext code generation.
  • Multiple-diagrams per model allows you to have several diagrams that visualize subsections of your overall model. Shapes on the design surface can also have coloring applied.
  • Table-Valued functions in an existing database can now be added to your model.
  • Batch import of stored procedures allows multiple stored procedures to be added to the model during model creation.

 

Here's a link to the getting started page of Entity Framework if you're new to it or want to see how to use features like Migrations.

Tags: , , , ,

Entity Framework | Software Development

Rotating text using CSS

by Victor 15. August 2012 21:18

This is a short style rule to help you rotate text in your html page using CSS.

 

.rotated-text {
    width:100px; height:20px; line-height:20px;
    -moz-transform: rotate(310deg);  /* FF3.5/3.6 */
    -o-transform: rotate(310deg);  /* Opera 10.5 */
    -webkit-transform: rotate(310deg);  /* Saf3.1+ */
    transform: rotate(310deg);  /* Newer browsers (incl IE9) */
    /* IE8+ - must be on one line, unfortunately */    -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=0.6427876096865394, M12=0.766044443118978, M21=-0.766044443118978, M22=0.6427876096865394, SizingMethod='auto expand')";      /* IE6 and 7 */    filter: progid:DXImageTransform.Microsoft.Matrix(M11=0.6427876096865394, M12=0.766044443118978,            M21=-0.766044443118978, M22=0.6427876096865394, SizingMethod='auto expand');   /*    * To make the transform-origin be the middle of    * the object.      */
    zoom:1;
    background:#ccc;
    font-weight:normal;
    margin:0 0 0 0;
}

Tags: , , , , , ,

ASP.NET | CSS | CSS3 | IE | Safari Development | Web Development

Get Date Part from a SQL DateTime

by Victor 9. August 2012 01:21

No matter how many times I used this, I always seem to forget. So, how DO you get just the date part from a DateTime object in SQL? Easy, like this:

 

DECLARE @someDate DATETIME
SET @someDate = '08/08/2012 10:15AM'
SELECT CONVERT(VARCHAR, @someDate, 101)

 

Try it, you'll see

Tags: , ,

SQL

DateTime functions in Entity Framework

by Victor 1. June 2012 20:06

If you try to use one of the system functions in a TimeSpan, DateTime, or DateTimeOffset you will get a "not supported" exception. That's because the function has no translation for the db provider. Thankfully, Microsoft added a handy utility function called EntityFunctions that implements the provider functions like AddDays. You can find them here:

 

http://msdn.microsoft.com/en-us/library/system.data.objects.entityfunctions.aspx

Powered by BlogEngine.NET 2.5.0.6

About Us

Wuji Touch is a software consulting firm based in Delray Beach, Florida. We specialize in Microsoft technologies, but we also have experience with Progress OpenEdge, iOS, and Android development. This is our blog. These are the tales of the pains and pleasures we experience daily in our journey through 1s and 0s.

Month List