Careful With Those Cookies

When doing testing, you might find yourself wanting to delete cookies for some URLs on your development machine.

Now, you need to be careful about how you delete these cookies, because Microsoft decided to pull a little trick on you.  They created a folder:

C:Documents and Settings[user]Cookies

This folder seems to contain all your cookies!  But, actually it doesn’t.  Deleting these cookies really doesn’t clear out the cookies you think you are deleting because the REAL cookies are stored in:

C:Documents and Settings[user]Local SettingsTemporary Internet Files

This folder contains cookies and other temporary internet files, but of the most importance here is that THIS is where you need to clear your cookies from.

I came across another thing on a recent project is that you can’t test for the existance of an outbound cookie.

If Response.Cookies.Item("ASDFA") Is Nothing Then
     Response.Write("This Will Never Execute")
End If

Why is this?  It is because with the Response.Cookies collection (but not on the Request’s cookies collection) when you request an item from the collection that doesn’t exist it CREATES it, with a value of an empty string.

 

Generating Resx Files For Globalization and Localization

Using resource files (resx files) for globalization is a standard technicque.  ASP.NET allows you to create 1 resx file per page to help you manage your content.

But when it is time to convert those files into the correctly named localized version to send to the translator, you might find yourself doing a lot of copying and renaming.

So I wrote a little script that does this for you:

Imports System.IO
Module Module1

    Sub Main()
        Dim languages() As String = {"es", "pl", "de", "fr"}
        For Each filepath As String In Directory.GetFiles("C:translationTest")
            If filepath.Contains("x.resx") Then
                For i As Integer = 0 To languages.Length - 1
                    File.Copy(filepath, filepath.Replace(".resx", "." & languages(i) & ".resx"))
                Next
            End If
        Next
    End Sub

End Module

This will generate all the files for you, and then all you need to do is send the off and wait for the translator to do the REAL work :).

FancyUpload Component

I recently wrote about how the Flickr Uploadr tool sucks, but the other part of that article was how the web upload tools for Flickr is very nice!

FancyUpload is a set of code using Flash/Javascript to perform out of band file uploads.

This is basically how Flickr allows you to queue files for upload in their web client, and it is very useful in this sense because it would be extremely painful to be forced to post every single image individually.

For me, I am more interested in the ability to post very large files without leaving the brower in a fashion that seems to make it look like it is “stuck” when really it is just uploading a giant file.

 

Globalization and Localization in ASP.NET

This is a good article from Microsoft on globalization and localization of asp.net applications.

The article describes how to automate the process of moving static content from pages (inside labels) into resource files and setup the proper binding between the content controls and the resource files.

This article has some interesting and useful information as well about some other topics such as global vs local, implicit globalization settings, dealing with scripts etc.

e.Item.Dataitem is nothing?

So you have some code running in your itemdatabound event handler and you are trying to do someting with e.item.dataitem but it keeps bombing out with errors because e.item.dataitem is nothing.

So, why is e.item.dataitem is nothing??

Answer: Because you are probably using a header or footer in your binding object.  The header/footer will cause the itemdatabound event to fire, but there is no dataitem for them.

Check if the current row is the header or footer, and then you will have no issues with using e.item.dataitem.

VS.NET Extensions for Sharepoint

My experience with developing for Sharepoint was very painful.  The jist of it was, unless you are truly going to hook into a lot of the core functionality of sharepoint (document collaboration and workflow) it will be MUCH harder to build an app to run in sharepoint than it would be to build a standalone application.

But MS has released some new extensions that will hopefully ease the pain a little bit:

Announcing: Visual Studio extensions for SharePoint – Developer User Guide

I don’t know if I will ever have enough time to implement anything in sharepoint, but these will be nice to have.

Using a STYLE block on a page with a Master Page

I have been asked this a few times, so I decided to write up a little article on it.

The problem is that when you are using master pages in asp.net, the <HEAD> is usually inside the master page template.  So if you are on a page that needs a 1 off change or addition to the style of the rest of the site, you are unable to create a <STYLE> element in your content page.

Well, you CAN create one, but then VS.Net won’t show you the designer for your page b/c it keeps asking you to clean up the HTML problems on your page.

The solution I have used is to create a 2nd content place holder in the master page head.  But, I might as well not duplicate effort here, as Rick Strahl has already written the article I am about to write (and apparently, even someone else beat him to the punch).

http://www.west-wind.com/WebLog/posts/5706.aspx

This works very well for this type of situation.