Updates from June, 2011 Toggle Comment Threads | Keyboard Shortcuts

  • Steve Lydford 12:12 pm on June 4, 2011 Permalink | Reply  

    Displaying CSV in an Excel Worksheet from ASP.NET 

    Several times in the past I have needed to provide CSV data to users for use in MS Excel. Previously I have written code to create the physical file on the server and then redirect the user’s browser to that file for download/opening. However this approach has two major drawbacks.

    1. You must have rights to create files on the server.
    2. You can easily end up with loads of temporary files on the server which need clearing.

    This morning I discovered a new way to achieve this without creating any physical csv files on the server by changing the content type and page header. The following code demonstrates this:

     

    @{
        Response.ContentType = "application/vnd.excel";
        Response.AddHeader("Content-Disposition", "attachment; filename=filename.csv");
    
        Response.Write("aaa,bbb,ccc,ddd,eee,fff,ggg");
        Response.Write("hhh,iii,jjj,kkk,lll,mmm,nnn");
        Response.Write("ooo,ppp,qqq,rrr,sss,ttt,uuu");
    } 


    This way no physical file is ever created and the document will be displayed in an Excel worksheet. It is important to note though that the user must have Excel installed for this to work or they will receive an operating system message asking them to choose a program to use to open the file.

    Digg This
    Reddit This
    Stumble Now!
    Buzz This
    Vote on DZone
    Share on Facebook
    Bookmark this on Delicious
    Kick It on DotNetKicks.com
    Shout it
    Share on LinkedIn
    Bookmark this on Technorati
    Post on Twitter
    Google Buzz (aka. Google Reader)
     
    • Murali Kartha 5:18 pm on March 7, 2013 Permalink

      Steve,
      It is amazing code. It worked for me once . Now it is still opening the excel , but no data in it. I checked the csv file and has data in it. What is wrong? please advice. Thanks

  • Steve Lydford 2:41 pm on August 26, 2010 Permalink | Reply
    Tags: ,   

    ASP.Net Sprite and Image Optimization Framework 

    Check this out…

    http://aspnet.codeplex.com/releases/view/50869

    This is an awesome release, giving developers the ability to use sprites in web pages, without all the hassle which (let’s be honest) puts most people off at the moment.

    For those who are unaware of sprites, they are a technique which became popular in the games programming arena in the 80′s where you combine all (or some of) your images into a single file and display just a portion of it at a time, usually using a top-left coordinate starting point, combined with a width and height to specify the part to be displayed. In games programming in the early days this was used extensively (and still is in a vast percentage of 2D games) as multiple cells of an animation could be combined in one sprite and loaded into memory once. This gave much smoother animation as you were simply displaying a different portion of the same image for each cell in an animation, rather that loading a new image in for each frame.

    Why is this good for web developers? Well, each image you load into a web browser requires a separate HTTP request. By combining all the images into a single (or couple of) HTTP requests you can significantly reduce page load times. Plus, remember the reason that sprites were invented in the first place…. Just think of all the cool and crazy things you could do with a sprite and a bit of jQuery to make rollovers, animations, etc.

    This framework enables the .Net developer to use sprites in a very straightforward way. It literally creates a combined image from the all images in a folder and allows you to use them as sprite images in the page, doing all the combining and css chopping up automatically for you. Plus you can seperate things out into subfolders and set maximum file sizes etc. You get all the benefit with virtually no cost in time or effort.

    This video by Scott Hanselman on Channel 9 and this one on Craig Shoemaker’s blog explain more.


    Get Microsoft Silverlight

    Digg This
    Reddit This
    Stumble Now!
    Buzz This
    Vote on DZone
    Share on Facebook
    Bookmark this on Delicious
    Kick It on DotNetKicks.com
    Shout it
    Share on LinkedIn
    Bookmark this on Technorati
    Post on Twitter
    Google Buzz (aka. Google Reader)
     
    • Windows Hosting Guy 2:00 am on July 14, 2011 Permalink

      Will try this. Thanks for the article.

      I have been using Spriteme, which is very good, but you still have to make changes manually to your css.
      If this works, that would be great help.

      Thanks

  • Steve Lydford 2:50 pm on July 9, 2010 Permalink | Reply  

    Print Friendly Made (Very) Easy 

    I love those web sites which just do a simple, useful thing very, very well. I’m thinking of sites like:

    and now I’ve found another. Print Friendly allows you to very easily give print functionality to any Internet web page by including a button like this:

    Any Web Developer will know that Print Friendly pages can be a bit of a nightmare, so this tool could save you a whole load of work. The site strips out ads, navigation and other “junk” and allows the user to do some basic selection of exactly what they want to print.

    However, there is no way for the developer to specify any formatting or which part (or parts)  of the pages are required for printing so, although it is fine in simple cases, you should probably not rely on it if your client wants specific formatting on printed documents.

    How many times have “Print Friendly Pages” been added as a scope change to a project you have been working on? This app may just give you the functionality you need without a huge extra cost to your client. So, although it should be used with caution, for easy printing of non-critical information (I’m thinking blogs, news articles, etc.) this is a great tool that can save a lot of time and effort.

    Digg This
    Reddit This
    Stumble Now!
    Buzz This
    Vote on DZone
    Share on Facebook
    Bookmark this on Delicious
    Kick It on DotNetKicks.com
    Shout it
    Share on LinkedIn
    Bookmark this on Technorati
    Post on Twitter
    Google Buzz (aka. Google Reader)
     
    • Taylor 11:06 pm on July 19, 2010 Permalink

      Hi, this is Taylor founder of PrintFriendly. Glad you like the product! :)

      Good points on allowing developers to specify formatting and which parts of the pages should be printed. We’ll try to add some of these features shortly.

c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel