Friday, November 13, 2009

Move SVN project to a different repository

I had an SVN repository containing multiple projects in location "D:\svn":
D:\>svnlook tree svn -N
I needed to move my project "jarmel" to a totally different repository (at How did I do that?
  1. Dumped the whole repository (containing all projects: TarantinoSamples, wilser, oscommercel, jarmel) into a file "svn.dump":
    D:\svnadmin dump svn > svn.dump
  2. Filtered the dump to include only the "jarmel" project.
    D:\svndumpfilter include jarmel < svn.dump > jarmel.dump
  3. Hand-edited the file jarmel.dump to remove the initial adding of root directory "jarmel":
    Node-path: jarmel
    Node-action: add
    Node-kind: dir
    Prop-content-length: 10
    Content-length: 10
  4. Hand-edited the file jarmel.dump to replace all paths "jarmel/x/y/z" with "x/y/z":
    Find: "Node-path: jarmel/"
    Replace with: "Node-path: "
    Find: "Node-copyfrom-path: jarmel/"
    Replace with: "Node-copyfrom-path: "
  5. Import the new repository into newly created directory "D:\svnjarmel":
    D:\>svnadmin load svnjarmel --ignore-uuid svnjarmel < jarmel.dump

Wednesday, September 16, 2009


A CookieProxy class to access cookies in a strongly typed way:
using System;
using System.Linq;
using System.Web;

public class CookieProxy
    public HttpRequest Request { get; set; }

    public HttpResponse Response { get; set; }

    public CookieProxy()

    public CookieProxy(HttpRequest request, HttpResponse response)
        this.Request = request;
        this.Response = response;

    public string GetCookieKey(string name)
        return string.Format("{0}", name);

    private string GetCookie(string name)
        if (this.Response.Cookies.AllKeys.Contains(this.GetCookieKey(name)))
            return this.Response.Cookies[this.GetCookieKey(name)].Value;
            return this.Request.Cookies[this.GetCookieKey(name)] != null ? this.Request.Cookies[this.GetCookieKey(name)].Value : null;

    private void SetCookie(string name, string value)
        HttpCookie cookie = this.CreateCookie(name, value);
        if (this.Response.Cookies.AllKeys.Contains(this.GetCookieKey(name)))


    public HttpCookie CreateCookie(string name, string value)
        HttpCookie cookie = new HttpCookie(GetCookieKey(name), value);
        cookie.Path = this.Request.ApplicationPath;
        cookie.Expires = DateTime.Now.AddYears(10);
        return cookie;

    // Sample cookie.
    public string Culture
        get { return this.GetCookie("Culture"); }
        set { this.SetCookie("Culture", value); }
And a property in your application's base page:
private CookieProxy cookies;

public CookieProxy Cookies
        if (this.cookies == null)
            this.cookies = new CookieProxy(this.Request, this.Response);
        return this.cookies;
How do I use it in a page?
string culture = this.Cookies.Culture;
How do I use it in a MasterPage or a UserControl?
string culture = this.Page.Cookies.Culture;
Oh, and there's a catch when you are using cookies with path - the path is case sensitive. Here's the code to get rid of the problem (place it in your Global.asax file):
void Application_BeginRequest(object sender, EventArgs e)
    // If the application path casing is different from ApplicationPath, retrieve the url again with proper casing to avoid cookies problems.
    string url = HttpContext.Current.Request.Url.PathAndQuery;
    string application = HttpContext.Current.Request.ApplicationPath;
    if (!url.StartsWith(application))
        HttpContext.Current.Response.Redirect(application + url.Substring(application.Length));

Monday, September 14, 2009

NUnit External Tool

Command:C:\Program Files\NUnit 2.4.8\bin\nunit.exe
Initial Directory:$(ProjectDir)/bin/Debug

Wednesday, September 9, 2009

The not-so-dark secret of File.WriteAllText

When you use this method using the overload with Encoding as third parameter, it writes this encoding's signature into the file. Using this method without the encoding parameter gives you a UTF-8 encoded file WITHOUT the signature. This actually helped me a lot, since I needed a UTF-8 file with signature. Though nowhere documented, this little feature saved me some hacking like this. Nice!

Monday, August 17, 2009

The curious/furious case of ArrayOfString class

If you happened to have a problem with Visual Studio generating an ArrayOfString class instead of simple string[] in your web service client proxy, then this might be useful:
You are getting the ArrayOfString in the client, because you are using Add Service Reference to add a reference to the asmx service. You can get the string[] in the client in one of two ways: a) by creating a WCF service instead of an ASMX service, and using Add Service Reference. b) by keeping the asmx service, and using Add Web Reference instead of Add Service Reference.
from: found through: If you are creating your web service client proxy in a separate class library project, (which you are forced to if you are using Web Site instead of Web Application and want to extend your proxy generated classes using partial classes), you have to make this a .NET Framework 2.0 project. Otherwise you won't even find the "Add Web Reference" option in the right-click menu, only "Add Service Reference".

Wednesday, April 15, 2009

Send all NHibernate SQL queries to console output

When using a separate XML file to configure NHibernate (e.g. the hibernate.cfg.xml):
<?xml version="1.0" encoding="utf-8" ?>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
      <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
      <property name="connection.connection_string">Server=(local);Database=NHibernateFAQ;Integrated Security=SSPI;</property>
      <property name="show_sql">true</property>
When using ActiveRecord and Web.config:
    <section name="activerecord" type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord" />
      <add key="hibernate.connection.driver_class" value="NHibernate.Driver.OracleClientDriver" />
      <add key="hibernate.dialect" value="NHibernate.Dialect.OracleDialect" />
      <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
      <add key="hibernate.connection.connection_string" value="Data Source=sss;User ID=uuu;Password=ppp;" />
      <add key="hibernate.show_sql" value="true" />
Thanks to:

Monday, March 30, 2009

Autowidening DropDownList (IE only!)

<asp:DropDownList ID="ddl" runat="server" Width="100px" onmouseover=" = 'auto';" onfocus="this.hasFocus = true;" onblur=" = 100; this.hasFocus = false;" onmouseout="if (!this.hasFocus) = 100;" />

Works in Internet Explorer only - in Firefox the control does not narrow back.

Saturday, January 31, 2009

Send file to browser

private void SendFile(string fileText, string fileName, string contentType) {
  this.Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
  this.Response.ContentType = contentType;
Typical content types: Text "text/plain" PDF "application/pdf" Got it from: Starting the download with a button inside an UpdatePanel? Register the button for a regular, not partial postback:

Tuesday, January 27, 2009

Page transfer effect that works in Internet Explorer (blendTrans effect)

I can never remember this.
<meta http-equiv="Page-Enter" content="blendTrans(Duration=0.0)">

Monday, January 19, 2009

Quickly check web page performance

Paste this somewhere in your codebehind, putting the dt definitions around the suspected code:
DateTime dt = DateTime.Now;
DateTime dt2 = DateTime.Now; 
DateTime dt3 = DateTime.Now; 
this.debugLiteral.Text = string.Format("<div>|{0}||{1}||{2}|</div>", dt, dt2, dt3);
And paste this somewhere in your aspx:
<asp:Literal ID="debugLiteral" runat="server" />