Whew!

After a marathon coding session, I finally have the new design online. I'm rather pleased with the design at the moment, and, hopefully, I'll remain just as pleased with in the coming months. You might have noticed ( if you didn't, notice it now ) the urls. I managed to get rid of the index.php in an extremely hackish way, but then, I tend to be anal-retentive about these kind of things. Also, the urls don't include subdomains anymore. While it seemed like a good idea back when it started, it started grating on my nerves the last couple of days. Undoubtedly, this is going to cause broken links and what-not, but hopefully everything will be back to normal in a couple of weeks.

There are a couple of things left to do still — namely, the contact form and the search results page...

Keyboard Shortcuts for Mouse-Haters

Life-saving keyboard shortcuts that will make your life better now that you know them. Windows-only. If you're a Mac user, go away. 1. ALT + SPACE + N = Minimizes the currently active window. 2. WINDOWS + M = Minimizes all windows. Or, you can also use WINDOWS + D to minimize/restore all windows. 3. ALT + PRINT SCREEN = Screenshot of the current window. ( <— Woohoo! ) 4. CTRL + TAB = Switches between windows in the current application. 5. CTRL + F6 = Same as above, except that the above sequence acts like an ALT+TAB for the application whereas this one just goes to the next active window. 6. WINDOWS + E = Opens Windows Explorer. 7. WINDOWS + L = Locks the computer. 8. WINDOWS + BREAK = Opens System Properties. 9. WINDOWS + CTRL + F = Opens computer search. 10. WINDOWS + R = Opens run.

There are also the well-known ( one hopes ) CTRL+C (copy), CTRL+V (paste), CTRL + X (CUT), CTRL+W (close active window), ALT+F4(close active application) that I couldn't possibly live without.

Read more at Keyboard Shortcuts for Windows

Free Template: Three Quarters

Yes, I realize that I don't have my design up yet. Between distractions (read: Vista) and problems (read: #$@#!*), it's a wonder that I'm as far as I am. I'm still hoping to get the design up this week.

Anyway, to make up for that: here's another free template that I made a couple of weeks ago:

Three Quarters Template Screenshot

As always, you can do whatever you want with it. A mention and a link isn't necessary but is very much appreciated. :-)

View the template

Download the template files

Three Ways to Catch Exceptions in ASP .NET

Before we get on with the article, a couple of quick announcements. Regular readers of this site know well my tendency to put this site through an obnoxious number of redesigns. Sometimes I feel like I'm in a never-ending design cycle, because I'm always tweaking something here or adding something there. Anyway, I once again found myself twitching to do a redesign. I hesitate to say that I got tired of the old ( well, current, as of this entry ) theme, because I still like it; however, it most definitely grew old. So: look for the new design soon — like over the weekend; definitely over next week. :-)

Moving on.

Catching Exceptions in a Method

public void DownloadPdf(string path)
{
 try
 {
  System.IO.StreamReader reader = System.IO.File.OpenText(path);
 }

 catch (System.UnauthorizedAccessException ex)
 {
  // Hey, you don't have access to the file!
 }

 catch (System.IO.FileNotFoundException ex)
 {
  // Hey, the file doesn't exist
 }

 catch (Exception ex)
 {
  // Something bad happened
 }
}

Catching Exceptions at the Page Level

protected override void OnError(EventArgs e)
{
 Exception exception = HttpContext.Current.Server.GetLastError();

 // Inform the user about the exception, log it, and do whatever 
 // else you want to do here.
}

Catching Exceptions at the Application Level

// In global.asax
protected void Application_Error(object sender, EventArgs e)
{
 Exception ex = HttpContext.Current.Server.GetLastError();

 // Do whatever with the exception here.
}

You might notice that catching exceptions at the application level is remarkably similar to catching them at the page level. This is good — one less thing for us to have to remember. :-)

Clearing Errors

What if you want to have your application continue on its merry way, not stop dead in its tracks because of the exception? For example, suppose the user is trying to upload a file and your application throws an exception because the file is too big. It would be nice if your application lets the user to continue working instead of taking him to the jarringly-ugly yellow page of death error page?

This is what happens when you catch an exception (aka, method 1), so you don't need to do anything special. However, it's a pain to have to wrap every single method in a try...catch block. The way to clear exceptions/errors with the other two methods is with the Server class' handy ClearError method:

 // In global.asax
protected void Application_Error(object sender, EventArgs e)
{
 Exception ex = HttpContext.Current.Server.GetLastError();

 // Do whatever with the exception here.

 HttpContext.Current.Server.ClearError();
}

Conclusion

You should, at some point, trap all exceptions that occur in your application. At the very least, you should redirect the user to a custom error page. Not only are the default error pages produced by ASP .NET horrendously ugly, they're usually unhelpful to the end-user. Also, they reveal information about your code, which is bad from a security-viewpoint. ASP .NET provides 3 very easy ways to trap errors in an application.

My favorite method — well, my second favorite method — of catching exceptions is using the Global.asax's Application_Error method. ( My favorite way is to use HttpModules, which I'm going to talk about in a future article. )

How To List All Stored Procedures in a Database

exec sp_stored_procedures

That's it. That single line/word will list all the stored procedures in the currently-active database.

DatabaseName.dbo.sp_stored_procedures

This line lists all the stored procedures in the specified database.

Another useful stored procedure is sp_helptext, which shows you the actual (SQL) stored procedure:

DatabaseName.dbo.sp_helptext StoredProcedureName

Using these stored procedures with a linked server is straight-forward, too:

NameOfTheLinkedServer.NameOfTheDatabase.DatabaseOwner.sp_stored_procedures

Free Template: Two-Tenths

Two-Tenths Template Screenshot

As always, you can do whatever you want with it. A mention and a link isn't necessary but is very much appreciated. :-)

View the template

Download the template files

Commenting Out Server Controls in ASP .NET

This is something I seem to be doing an awful as of late. I start out with some control (say a GridView), then switch to some other control (say a Repeater), but I don't want to delete the GridView control until I get the Repeater control working.

You might have tried commenting out the control the HTML way — i.e., <!--...--> — and you probably found out that ASP .NET engine still parses it. Until recently, I was dealing with this the hard way: cutting & pasting the control into Notepad.

No longer.

Enter Server Comments

Namely:

<%--

 <asp:GridView ID="ProductsGridView" runat="server" DataSource="ProductsDataSource">
 </asp:GridView>

--%>

ASP .NET will ignore everything within a server comment block.

One Penny

One Penny Template Screenshot

Feel free to do whatever you want with it as long as it doesn't involve making money off of it. As always, a mention and a link though not required is appreciated very much.

A Wordpress theme based on this template is forthcoming. So stay tuned.

[ View the template ]

[ Download the template files ]

12 of 17 pages « First  <  10 11 12 13 14 >  Last »

On the Side