31 Mar 2009

Undocumented SQL Server Stored Procedures

This article documents some groovy system stored procs:


Sprocs include stuff like "FOR EACH DB/TABLE DO X" and "GET QUALIFIED OBJECT NAME".

Mucho useful. Now why the hell are they secret?

12 Mar 2009

Embed images in your web DLLs

You can embed all sorts of stuff into an assembly - javascript, css, pdf etc. Here I quickly detail how to embed an image file.

1. You have a solution with a web project and a separate class project
2. In Visual Studio, drag the image you want to embed into your class project
3. In the Properties window of the Image, select Build Action: Embedded Resource
4. Add a new class to the project, call it EmbeddedResources.cs for the sake of argument. Put the following code in it:

[assembly: WebResource("YourProjectAssemblyNamespace.YourPic.jpg", "image/jpeg")]

namespace YourProjectAssemblyNamespace
public class EmbeddedResources

5. Reference the image from your web project like so:

<img src="<%= Page.ClientScript.GetWebResourceUrl(typeof(YourProjectAssemblyNamespace.EmbeddedResources), "YourProjectAssemblyNamespace.YourPic.jpg") %>" />


Resolve Virtual Path From Physical Path (ASP.NET)

Quick code snippet to help people who want to derive a Virtual (web) path from a Physical (file) path:

string strVirtualPath = VirtualPathUtility.ToAbsolute("~/" + strPhysicalPath.Replace(Request.PhysicalApplicationPath, "").Replace("\\", "/"));

VirtualPathUtility FTW!

5 Mar 2009

.NET Regular Expression Reminder

I must be dense - I *heart* regex but every time I need to use one in .NET, I spend about 5 minutes trying to remember

  • what the right grouping character is
  • whether I need to escape it or not
  • which Regex class to start with
  • what the right terminology is for getting the sub-matches out of the match etc.
Which is weird cos when I was king of perl I could do this stuff lickity split. So I guess MS just like making it confusing. Evidence 1 - the regex syntax in Visual Studio is totally different to that in .NET. Duh.

Anyway here's a handy reminder to myself:

string strServer = System.Text.RegularExpressions.Regex.Match(strCon,"Data Source=(.+?);").Groups[1].Value;

Note the (.+?);
The trailing ? forces the match not to be greedy and only match up to the first semi colon.
If I helped you out today, you can buy me a beer below. Cheers!