[ASP.NET MVC] How to render a report to excel

- First you need to create an action that returns a ContentResult
- In that action you create a new ContentResult and set the content type to “application/vnd.ms-excel”
- In the ContentResult you set the Content to an xml representation of an excel document ( refer to wikipedia: http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats )
- return said ContentResult and a user browsing your page will be prompted to open up excel and view your report.

Code Snippet here: http://gist.github.com/94542

Leave a Comment

Encouraging Open Source in .NET

At the seattle alt.net meeting a couple weeks ago there was an interesting talk on encouraging open source in .net.

You can check out the video here: http://www.vimeo.com/3487604

There were a bunch of interesting ideas thrown around, but here are some things that stuck with me.

One lady said that a problem with open source in .NET is that it is too hard to integrate open source tools and libraries with your visual studio environment. The group kind of dismissed this idea, saying that .NET developers are smart enough to add reference a .dll.

However, if you browse projects on codeplex you will find that many of them don’t release a dll download. So you are forced to download a zip file with the visual studio project, build it, and then take the created dll and import it into your project. .NET open source developers need to really focus on the end user experience if they want to see any uptake in their products.

On that same note, codeplex should steal some features from github. Github is much more useful than codeplex because github is prettier, more user friendly, more responsive, has a documentation oriented focus ( you can create wikis, pages, embed images, and whatnot ), you can browse code in your browser. Github is really just great and a .net equivalent would be much appreciated.

Documentation is key if you want your open source project to get uptake. Check out hpricot for an example of a project that is managed very well. It is ruby and its creator really focuses on his explanations and teachings.

There was a lot of doom and gloom in the talk, but really I think there is a lot of good open source .net work being done. Obviously nhibernate, nunit, nmock are very popular projects. Also a lot of cool stuff is going on with the mvc contrib. In the past few years open source in .net has really taken off. The future is bright my friends.

Leave a Comment

What is opencalais and how to play with it in ruby

Opencalais is a really cool project put out by Reuters which lets you categorize blocks of text. If you do any kind of feed aggregating, opencalais is something that you should look into. Also if you use any user generated tags, opencalais could be a solution to replace them automatically with computer generated tags from text.

For example, if you submit an article about the houston rockets playing the dallas mavericks, it will extract the team names as well as any quotes that are in the article and the general article topic and then send that back to you via xml.

It definitly is a cool project you should check out: www.opencalais.com/

Here is some code in ruby to connect:

Ruby code to connect to opencalais

Comments (1)

Creating a simple datagrid in ASP.NET MVC

1) In your controller, query all of the records from the database using LINQ to SQL and pass the data to the view:

AppsDataContext appsdata = new AppsDataContext();
var all_apps = from a in appsdata.apps select a;
ViewData["apps"] = all_apps;
return View();

2) In your view, iterate through the apps, make sure to cast the ViewData value as System.Linq.IQueryable, put the data into a html table

<table border=”1″>
<tr><td><b>First Name</b></td><td><b>Last Name</b></td></tr>

<%       foreach (var a in (System.Linq.IQueryable)ViewData["apps"]) %>
<% { %>
<tr>
<td><%= ((Models.app)a).firstname1 %></td> <td><%= ((Models.app)a).lastname2 %> </td>
</tr>
<% } %>

</table>

3) style your html table as you like and add links where needed to get whatever traditional datagrid functionality you desire.

Leave a Comment

Weekend ruby MMO project

Inspired by this post: http://www.gamedev.net/reference/articles/article2259.asp

I decided to try my hand at creating an MMO in a weekend with ruby. I always thought it would be cool to have an original 2d zelda style MMO.

Using ruby was a breeze. The gosu game engine project is easy to work with and GServer is a great library for creating servers of all types.

Well basically, I ran into some scheduling issues and I am not that close to finishing. But I will probably work a few more weekends on this. After one weekend I have:

  • character moving around the screen and firing weapon
  • world map with 10×10 map tiles and randomly generated rock terrain
  • Game server working allowing infinite ( theoretically ) connections
  • Game server chat working

Still to come:

  • Game server movement and collision
  • items
  • quests/point to the game

mmoscreenshot

Code is located at http://github.com/browning/zmmo/tree/master

Leave a Comment

How to teach computer programming to blind people

Programming is hard to learn. Most people that try to learn it will dislike it and quit.
I think there are a few things that help the average programmer learn.

  • Scripting languages – the instant feedback allows for trial and error and it is a lot easier to get the ball rolling
  • FUN – programming should be fun ( at least at first ). For most people this means making games.
  • Give you something to show off – again for most people this means making games

I think a HUGE number of current programmers learned how to program by making games ( especially in BASIC back in the day ). Of course there are some who were excited by quicksort from day 1 and then whizzed through SICP and never looked back. But for the average person, game programming is a great way to get acquainted with programming. It teaches all the basic skills and it lets you make things that are IMPRESSIVE as well as FUN. Once you learn how to program through games, then you can branch out to whatever specialty you fancy ( web apps, databases, enterprise apps ) and you will be prepared.

However, if you are blind, making games wouldn’t be that much fun. Screenreaders really aren’t to the point where they can tell you what a 3d scene looks like. Is there another less visual programming niche that is easy to approach and fun?

Yes, it is

MUSIC

Music is fun. And through music, I believe you can learn all of the basics of programming. Songs can be represented as arrays of notes. Instrument -> brass -> tuba hierarchies can illustrate object oriented programming. The different instruments in a band can teach threading. And so on and so on.

The problem with most music libraries for most languages is that they are fairly complex and are difficult to get up and running.

I am working on a midi ruby project with some people that changes that barrier. Playing a note is one line of code.

play 44

Changing your instrument is also one line of code:

instrument 25

With these simple building blocks, an entire programming syllabus can be laid out and taught. I’ll have more on this later, but please leave feedback and if you feel like trying it out or contributing the code is located at in the ruby_tunes.rb and ruby_tunes_play.rb files:

http://github.com/Gabrielg1976/ruby_music_projects/tree/master

a small tutorial is on the wiki here:

http://wiki.github.com/Gabrielg1976/ruby_music_projects/tutorials

Comments (1)

ASP.NET pro magazine article on XML vs JSON

There is a really good article in asp.net pro magazine this month about using JSON in .net applications. I highly recommend you check it out. Many .net developers use xml for basic object representation and they rarely use the more advanced features of xml. If you are just wanting to represent an object you should definitly look into JSON. Its a lot easier on the eyes and parsing JSON in javascript is just a whole lot easier with eval().

In my latest ajax project, I exclusively use json and the whole process has been a breeze. I will write more on that project later, but just wanted to give you a heads up on the article.

Posted by email from Brian’s posterous

Leave a Comment

Reset ASP.NET password from the database

If something goes bad in your application and your passwords get mangled,  you may find yourself locked out of your asp.net application with no way to get in.

This is a quick fix to the database that can get you back on the path to recovery.

Lets say you have a user called 'bob' and you can't remember the password:

1) Open up the ASPNETDB database in sql express or whatever sql explorer you use
2) Open the aspnet_users table
3) Find the line that has the bob value for username and make note of the UserId value
4) Open the aspnet_membership table and find line with that UserId
5) Paste this into the password column: VywrWJE0sfZClxYSzhSfL8MZ5BM=
6) Paste this into the passwordsalt column: pQ/5FFMkhYpy+H9zdX229w==
7) Now you should be able to log into your application using the 'bob' username and the password 'newpwd@3'
8) You can then change the password using your application's normal password change mechanism

Posted by email from Brian’s posterous

Leave a Comment

ASP.NET: cannot log in to site on production server

If you are using AspNetSqlMembershipProvider in your web.config, a situation may arise where you can log in fine on your development box, but when you move your app to another server the login fails with a invalid username or password error.

This is fixed by adding applicationName="/" to the AspNetSqlMembershipProvider section like so:

<add name="AspNetSqlMembershipProvider"
                  type="System.Web.Security.SqlMembershipProvider, System.Web,
        Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
                  connectionStringName="LocalSqlServer"
                  applicationName="/"
                  requiresQuestionAndAnswer="false"
                  requiresUniqueEmail="false"
                  passwordFormat="Hashed"
                  minRequiredNonalphanumericCharacters="0"
                  minRequiredPasswordLength="3" />

Posted by email from Brian’s posterous

Leave a Comment

Find related tags in acts_as_taggable_on_steroids

A cool feature in the rails plugin acts_as_taggable_on_steroids that I haven’t seen documented in a lot of the tutorials that I have seen is the ability to find related tags.

So lets say that I have a bunch of shoes that are tagged with different descriptors and I want to find all of the tags that are on objects tagged with ‘running’ and ‘nike’

My model name is Shoe.

tags = ['running', 'nike']
related_tags = Shoe.find_related_tags(tags)

Easy!

Leave a Comment

Older Posts »
Follow

Get every new post delivered to your Inbox.