April 21, 2005

Using Enumerated Types in C# as Bit Flags

example

[Flags]
  public enum Layout : byte //<= specify UNDERLYING type here
  {
    CentreColumn = 1,
    LeftColumn = 2,
    RightColumn = 4
  }
  
  private Layout m_Layout = Layout.CentreColumn | Layout.LeftColumn
| Layout.RightColumn; ... // USAGE m_Layout.ToString(); // => Gives "'CentreColumn, LeftColumn, RightColumn'" // Going the other way Layout m_Layout = (Layout)Enum.Parse(typeof(Layout), "CentreColumn, LeftColumn"); Layout m_Layout = (Layout)4; // => m_Layout = RightColumn

April 14, 2005

Weblog Sample

Took a closer look at http://www.codeproject.com/soap/weblog.asp. Tested it on my PC and it worked. Had to copy the Weblog project to my Inetpub directory and set it as an web application using the ComputerManager=>Services and Applications=>InternetInformatioServices tool.There are some useful techniques to learn from this sample. The way it uses passwords to access a webservice. I also like the fact that it persists the data direct to an XML file rather than some database. Managed to get editdvdcollection.aspx to write the updated dvdcollection.xml file correctly. I had to remove the TITLE, DESCRIPTION and LASTUPDATED elements from the COLLECTION node and then just regenerate the xsd. Makes me wonder how the DataSets handle complex XML. What if I kept these elements but put all the ENTRY nodes under a single ENTRIES node could I get the code to work then. I havent got time to investigate this I just want something that works. Next I need to work out how an aspx web page can accessed using only secured (via a password) users. I want access to a web page for everyone but the editing facilities only available to those who are logged on. When I started writing the Freelancer XSL I got used to the two different forms ways of processing nodes. I like the idea of writing a rule to match a node no matter where it is in the sequence and processing it. However sometimes you want to choose a particular node and ignore all the rest. This is why I had got used to the named template style. When writing xsl decied if all the nodes of a certain type will be output. If so use a rule to match against it, if not the parent node will have to select the interseting node or nodes and invoke a named template on them.

xsl:sort

Learned about using 'xsl:sort'. Its very easy just put it after the for statement. Specify what of part of each node processed by the 'for' dtatement is to provide the basis of the sort.

xsl:import

Got 'xsl:import' to work. Found that unlike the 'xsl:include' it has to be straight after the xsl:stylesheet' definition

Compiling an ASP.NET dll by hand

>csc /t:library /out:bin\dvdcollection.dll /r:System.dll /r:System.Web.dll dvdcollection.aspx.cs

EnableViewState="false"

<%@ Page EnableViewState="false" %> Use this to turn off ViewState in an aspx page. Its not needed unless there are controls in the page.

TechInterviews -
What does the "EnableViewState" property do? Why would I want it on or off?

Enable ViewState turns on the automatic state management feature that enables server controls to re-populate their values on a round trip without requiring you to write any code. This feature is not free however, since the state of a control is passed to and from the server in a hidden form field. You should be aware of when ViewState is helping you and when it is not. For example, if you are binding a control to data on every round trip (as in the datagrid example in tip #4), then you do not need the control to maintain it’s view state, since you will wipe out any re-populated data in any case. ViewState is enabled for all server controls by default. To disable it, set the EnableViewState property of the control to false.