Showing posts with label how to. Show all posts
Showing posts with label how to. Show all posts

Friday, September 10, 2010

Thursday, July 15, 2010

How To Get DateTime In XSLT

It's actually quite easy, though definately not obvious, to perform a fairly standard =DateTime.Now operation in XSLT, even when using C# (the default Microsoft XSL parser is only on version 1.)

Here's the XSLT:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:my="urn:sample" extension-element-prefixes="msxml">

<msxsl:script language="JScript" implements-prefix="my">
function today()
{
return new Date();
}
</msxsl:script>
<xsl:template match="/">

Today = <xsl:value-of select="my:today()"/>

</xsl:template>
</xsl:stylesheet>

Here's the C#:

/// <summary>
/// Takes a string containing XML to be parsed and a string containing the the XSLT to do the parsing.
/// </summary>
public static string XSLTransformation(string xml, string xsl)
{
// create the readers for the xml and xsl
XmlReader reader = XmlReader.Create(new StringReader(xsl));
XmlReader input = XmlReader.Create(new StringReader(xml));

// create the xsl transformer
XslCompiledTransform t = new XslCompiledTransform(true);
XsltSettings settings = new XsltSettings(false, true);
t.Load(reader, settings, null);

// create the writer which will output the transformed xml
StringBuilder sb = new StringBuilder();
XmlWriterSettings tt = new XmlWriterSettings();
//tt.Encoding = new UTF8Encoding(false);
XmlWriter results = XmlWriter.Create(new StringWriter(sb)); //, tt);

// write the transformed xml out to a stringbuilder
t.Transform(input, null, results);

// return the transformed xml
return sb.ToString();
}

References:

Tuesday, March 09, 2010

Drive Space Disappearing Captain!

Being very mystified recently that my drive apparently kept filling up, no matter how much space I freed by file deletions, I went on the hunt for any directory et al that might be growing, uncontrolled.

My journey took me to the directory:
  • C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data
Where I found a "nnn_log.ldf" file which was over 50% of my total drive capacity.

Upon opening "SQL Server Management Studio" I found the database in question, opened the Properties dialog and clicked on Files, in the left-hand list of panels. There, under the "Autogrowth" field of the "Database files:" display was a happily chugging "By 10 percent, unrestricted growth".

Simply changing the restricted size to something sensible did not work as hitting Ok threw an error dialog up.

A quick Googling later and this showed up:
So, to get rid of an overly large log file attached to the DB, the process is thus:
  • Take DB offline
  • Detach DB (Untick "Keep Full Text Catalogs", if that is the problem part)
  • Delete the overly large file
  • Re-attach DB, removing the LDF file from the "database details" gridview
  • Click "No" to skip re-attaching the log files/full text catalog (you've deleted it)
  • Open the DB's "Properties -> Files" dialog
  • Under "Autogrowth" click "..."
  • Untick "Enable Autogrowth"
  • Click Ok
For your DB, you should now have removed any overly large files and stopped any existing files from getting any bigger. Of course, if you do need them to grow, just keep an eye on the Autogrowth properties.

Sunday, November 01, 2009

XSLT, XPath Knowledge Base

XPath explained and easy-to-use grid of descriptions...
Very useful XSLT scripts (including url encode/decode templates)...
A list of XSL elements and descriptions...
.NET 3.5 page on navigating XML in XPath...
Using XPath and LINQ...

Sunday, September 06, 2009

Loving Up The iPhone

Finally made the switch from a dying T-Mobile Windows Mobile MDA Vario II, to the 16GB iPhone 3GS and it's awesome! This thing completely surpasses all expectations in performance, usability, speed and sheer number of applications available - there are far more applications than for Windows Mobile and they are so easy to get. The addictive nature of downloading to the iPhone, I think, would compare to the discovery of P2P file sharing.

Anyway, I was disappointed when I discovered (yes, lots of this is new to me) that I can't just dump files onto the iPhone like I can with the iPod (using it as an external HD, for example) or that ringtones cannot be selected from any music on the device. I did, though, find a very good page with instructions on how to do this. Originally written, then tidied up, for the iPhone 3G, this page is accurate for 3GS as the method is fairly generic;
In short, it goes like this:
  1. Get an audio file and edit to around 20-30 seconds
  2. Save as MPEG-4 (.m4a - see WavePad for easy converting)
  3. Change file extension to .m4r
  4. Drop into the Ringtones section of iTunes
  5. Sync Ringtones to your iPhone
The ringtones will now be available in the Sounds section of you iPhone's settings. Easy. There is more detail on the above link and a pointer to the http://audiko.net/ site for even easier conversions, but manual conversion was my preference (and is really very easy.)

WavePad is available here:
On the other side of the coin, we have videos for the iPhone. As with iPod and iPod Touch, there are plenty of videos to purchase or stream (iPhone comes with a YouTube app) but what if you have a load of wmv's or avi's you want to just dump there? I would get the iPod/iPhone video converter Videora because it has all the "want that one" simple functions that you could need, while being fast and producing quality output. Then it's simply a case of syncing your iPhone to your videos (videora can auto-add conversions to iTunes' library or you can manually drop them onto the phone) to make them play on the iPhone.
Red Kawa, the makers of Videora, even have easy-to-use apps for making wallpapers for the iPhone, but with the wallpaper selector built in, I don't think those are necessary.

Tuesday, June 30, 2009

Creating A Shortcut To Open Current File In Explorer From Visual Studio

Here's a neat little item that most people won't know about in Visual Studio 2008 - opening the directory of the current file in windows explorer:

Friday, April 10, 2009

P2P What I/You Need To Know

Ok, first off: If articles like this http://lifehacker.com/371653/caught-downloading-copyrighted-materialnow-what or this http://gizmodo.com/5066280/almost-half-of-net-traffic-is-not+so+legal-p2p-and-itll-really-take-off-soon scare you, you should probably stop right here, uninstall whatever P2P software you have and signup for online Blockbuster or something (there are better services, not to mention the online ones!) because actually downloading potentially illegal files will scare the socks off you. That's not to say it's scary, difficult or even illegal - if done RIGHT.

Secondly, I'm not advocating sharing illegal files. I pretty much subscribe to this 'manifesto', if you will: http://i.gizmodo.com/5202399/a-pirates-code-of-conduct-for-bittorrent. Personally, I do not intend to break copyright laws, rip-off artists or content producers and I certainly intend to actively help struggling industries, like the British movie industry, because I want movie makers like Simon Pegg and Ricky Gervais to keep me entertained. If the niche, intelligent and truly original creators are supported we will be kept wallowing in Shakespearian quality media for a long time to come!

Having read recently the following articles on LifeHacker and Gizmodo:
I thought it would be appropriate to bone up on some P2P security and best practices. Not that I do P2P, of course. Having said that, it would be nice if the content providers out there were to realise that if they provide customers (ie: potential customers/file-sharers) with what they want they would instantly become loved and extremely rich and probably immediately end the global crisis (new jobs, lots of new customers, new shows - all would be possible tomorrow.)

For starters, on the subject of P2P file sharing, there is the whole security thing, which LifeHacker and Gizmodo have neatly covered in a reader friendly way:
Amongst those articles, you'll find useful links for things such as:
And finally, good information comes in all forms, and on the internet this means the best way to find up-to-date links. I like tagged articles on well circulated sites, for example:

Sunday, March 15, 2009

Microsoft links I have yet to read, but really should...

How Do I: Create a Breakpoint
Using Conditions?

How Do I: Create a Breakpoint Using Hit Count?

How Do I; Learn Tips and Tricks for Debugging in Visual Studio?

Office Development with Visual Studio Developer
Center Just Launched!

Microsoft Cloud Computing Tools

How Do I: Add Tool Windows to the Visual Studio IDE?

How Do I: Add a New Tool Window to Visual Studio?

How Do I: Integrate With the Error List?

How Do I: Create a Basic Language Service Using the Managed Babel System?

How Do I: Create Custom
Project Templates Using Visual Studio 2008?

How Do I: Create an Item Template Using Visual Studio 2008?

How Do I: Write to the Output Window?

Explore the New Features of Visual Studio 2008

How Do I: Create a Debugger Visualizer?

How Do I: Place My Commands Into Different Kinds of Visual Studio Menus?

How Do I: Add Commands
and Controls Into the Visual Studio IDE?

How Do I: Get Started with the VisualStudio Domain Specific Languages?

Heroes Happen Here
DotNetNuke® and Visual Studio 2008

Visual Studio Tip of the Day

How Do I: Add AJAX Functionality to an Existing ASP.NET Page?

How Do I: Debug a Windows Presentation Foundation Application in Visual Studio 2008?

How Do I: Use the LINQ-Enabled
XML API in Visual Studio 2008?

Friday, June 20, 2008

Getting ASP.NET Authentication in SQL Working

Firstly, you could go here, which helped me: http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx

Otherwise, just go to: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

Run the aspnet_regsql.exe and following through the Next button.

If you want to setup a connection to your local machine running sql express, be sure to enter <machinename>\<sqlserver> for example: MATTSMACHINE\SQLEXPRESS

Everything should now be setup.

The next bit is optional, but I like to go to: http://msdn.microsoft.com/en-us/library/cc467894.aspx

Get the latest build of the Microsoft Enterprise Library. The setup is fairly simple, just install and follow the instructions for setting up the web.config and connection strings for allowing the data access layer. This will provide easy to use connection pooling and everything you need for single command SQL execution on your db.

The important entries in your web.config file should be:

<configSections>
<section name="dataConfiguration"...
...
</configSections>
<connectionStrings>
<add name="chopDatabaseConnection" providerName="System.Data.SqlClient"...
...
<dataConfiguration defaultDatabase="chopDatabaseConnection"/>

And you're away!

You might also want to read this: