Friday, April 27, 2007

Getting a fully qualified url for a page

You have an ASP.NET application. Your application creates an email let's say. In the email you want to show a link back to a page in your application. Believe it or not, there is not a pre-packaged method in ASP.NET that does this. Here is the solution. /// <summary> /// Changes a relative path such as /MyPage.aspx or ~/MyPage.aspx to /// a fully qualified path such as http://myhost/myAppPath/MyPage.aspx /// </summary> /// <param name="pagePath">relative path page need fully qualified path for</param> /// <returns>fully qualified path</returns> public string GetFullyQualifiedPath(string pagePath) { string absUrl = string.Empty; HttpRequest request = HttpContext.Current.Request; Uri url = request.Url; string host = url.DnsSafeHost; string appPath = request.ApplicationPath; absUrl = string.Format("http://{0}{1}{2}", host, appPath, pagePath).Replace("~", ""); return absUrl; } Here is another way to do it also. Same idea. public static string GetFullyQualifiedUrl(string relativeUrl) { string host = HttpContext.Current.Request.Url.Host; int port = HttpContext.Current.Request.Url.Port; UriBuilder uriBuilder = new UriBuilder("http", host, port, relativeUrl); string fullyQualifiedUrl = uriBuilder.Uri.AbsolutePath; return fullyQualifiedUrl; }

If you just want to know the url of the page that is requested, here is the simplest way to do this.

string url = HttpContext.Current.Request.Url.ToString();

For more information on paths, check out this blog:

Monday, April 9, 2007

See if page is valid from JavaScript

I did a little digging through the javascript code that ASP.Net uses to do its client-side (javascript) validation to figure out how ASP.Net knows if the page or group is valid or not before submitting the form. Here is the hack you can use to do it yourself. // a empty string means page. var validationGroupName = "";

if (typeof(Page_ClientValidate) == 'function') { var validationResult = Page_ClientValidate(validationGroupName); if (validationResult == true) { // do your cool javascript stuff here. This will only happen if the page or group is valid } }

Visual Studio 2005 solution file location for WebSites

Visual Studio 2005 doesn’t prompt you where to save the solution file for a web site like it did in Visual Studio 2003. It is creating a solution file though.

The location is:

C:\Documents and Settings\<username>\My Documents\Visual Studio 2005\Projects

If it gets lost or deleted, Visual Studio 2005 can recreate it.

Also, if you want to see the solution in Solution Explorer in Visual Studio 2005, you can look in the Options for the IDE. There is an option to always show solution file.

Tools menu | Projects and Solutions | Always show solution

Wednesday, April 4, 2007

Outlook Keyboard Shortcuts or button to Move a Message to a Folder

Are you a fan of the Google Gmail Archive button that moves your current message to the Archive so you never have to look for it again. Then this blog is for you. I walk you through how to create this functionality in Outlook 2003.
Create a macro in Outlook.
Sub ArchiveIt()
On Error Resume Next
Dim objFolder As Outlook.MAPIFolder ' Folder where we want to move select of messages Dim objInbox As Outlook.MAPIFolder ' Archive Inbox
Dim objNS As Outlook.NameSpace Dim objItem As Outlook.MailItem
Set objNS = Application.GetNamespace("MAPI") 'Find Domino Mailbox Set objInbox = objNS.Folders("Archive Folders") 'Find Archive Inbox Set objFolder = objInbox.Folders("Inbox")
'Assume this is a mail folder If objFolder Is Nothing Then MsgBox "This destination folder (called Inbox) doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER" End If
If Application.ActiveExplorer.Selection.Count = 0 Then 'Require that this procedure be called only when a message is selected Exit Sub End If
For Each objItem In Application.ActiveExplorer.Selection If objFolder.DefaultItemType = olMailItem Then If objItem.Class = olMail Then objItem.UnRead = False objItem.Move objFolder End If End If Next
Set objItem = Nothing Set objFolder = Nothing Set objInbox = Nothing Set objNS = Nothing
End Sub
Create a digital signature so it can be run again using the button or key stroke.
Run C:\Program Files\Microsoft Office\OFFICE11\SelfCert.exe
Use the digital signature to sign your macro:
Open the macro in the macro editor. Then go to Tools menu and click the Digital Signature menu item. Choose the certificate (if it is not already chosen).
Create a tool bar and toolbar button. Assign a key stroke to it if you like. That is it.