28 April 2011

How to Rebuild the Icon Cache in Windows Vista and Windows 7

My earlier post Incorrect icon shown for a file type in Vista (March 31, 2008) tells you how to refresh the shell icons in Vista. In case the solution posted in that link does not help, you may want to clear the icon cache database. The icon cache can be cleared by deleting the hidden file named IconCache.db in the following location:

%userprofile%\AppData\Local

Note: %userprofile% represents the path to user profile folder.

Rebuilding the Icon Cache Database

1. Close all folder windows that are currently open.

2. Launch Task Manager using the CTRL+SHIFT+ESC key sequence, or by running taskmgr.exe.

3. In the Process tab, right-click on the Explorer.exe process and select End Process.

4. Click the End process button when asked for confirmation.

5. From the File menu of Task Manager, select New Task (Run…)

6. Type CMD.EXE, and click OK

7. In the Command Prompt window, type the commands one by one and press ENTER after each command:

CD /d %userprofile%\AppData\Local
DEL IconCache.db /a
EXIT

8. In Task Manager, click File, select New Task (Run…)

9. Type EXPLORER.EXE, and click OK.

 


 

An even easier way:

cmd /c taskkill /f /im explorer.exe && del %LocalAppData%\IconCache.db /a && explorer.exe

 

Trovato qui.

26 April 2011

Adding Facebook Share functionality to an ASP.NET web site with a Master Page

This article assumes the reader has experience developing web sites using ASP.NET, specifically using Master Pages. It also assumes a familiarity with Facebook. All sample code is in C#. After reading this article, you should be able to integrate Facebook Share with an ASP.NET web site, whether or not it contains a Master Page. I’ve chosen to illustrate this using a Master Page because it’s a little more involved, and once you can do it with a Master Page, you should be able to do it without one as well.

What is Facebook Share, and how does it work?

First, let’s review what Facebook Share actually is. Adding a Share widget to a web page allows a user to click on an icon which launches a Facebook Share dialog. If the user has a Facebook account, they can then share the web page on their Facebook “wall” with their friends on Facebook, adding comments if they so choose. Their friends will have the opportunity to share with their friends, and so on. In this way, a web page’s exposure can increase dramatically in a very short time.

According to the Facebook web site’s documentation there are five steps you need to take in order to integrate Share with a web page:

Step 1: Add a link to the Facebook Share application hosted by Facebook:
<a name="fb_share" type="button" 
href="http://www.facebook.com/sharer.php">Share</a>

Step 2: Add a script tag that points to a Javascript component hosted by Facebook:
<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" 
type="text/javascript"></script>

Step 3: Add a meta tag containing the title of the page:
<meta name="title" content="This is the Title" />

Step 4: Add a meta tag containing a description of the page:
<meta name="description"
content="This is a short summary of the page." />

Step 5: Add a link tag pointing to an image to be used as a logo:
<link rel="image_src" 
href="http://www.murrayhilltech.com/images/LogoColorNoText.jpg" />

The problem

All well and good, but we were talking about doing this while using a Master Page. See the problem yet? Well, if all the pages in our site use a common Master Page, which presumably contains the head tag, which in turn contains all the meta tags and link tags, how do we specify different tag values for different pages? Therein lies the problem. The solution lies in the code-behind file.

The solution

I’ve chosen to place the code for Steps 1 and 2 in the actual web page as opposed to the Master Page, since that will allow us the flexibility to place the Share widget in varying locations on each page should we care to do so. However, I’m going to accomplish this by inserting an empty asp:Label component in the desired location in the aspx file, and assigning the appropriate value to it in the Page_Load event in the code-behind file. I’m going to use the same asp:Label component to hold the code for both Steps 1 and 2:
// This code for the asp:Label component goes in the aspx file

<asp:Label ID="labelSteps_1_2" runat="server" Text=""></asp:Label>

// The code to populate the asp:Label component with the html and script code
// for Steps 1 and 2 should go in the code-behind file

labelSteps_1_2.Text = "<a name=\"fb_share\" type=\"button\"></a>" +
    "<script src=\"http://static.ak.fbcdn.net/connect.php/js/FB.Share\" " +
    "type=\"text/javascript\"></script>";
Next, we’ll instantiate a couple of HtmlMeta objects to handle the meta tags in Steps 3 and 4, also in the Page_Load event:
HtmlMeta tag = new HtmlMeta();
            tag.Name = "title";
            tag.Content = “This is the Title”;
            Page.Header.Controls.Add(tag);

            HtmlMeta tag = new HtmlMeta();
            tag.Name = "description";
            tag.Content = “This is a short summary of the page.”;
            Page.Header.Controls.Add(tag);
Finally, we’ll add the logo in Step 5 in the same Page_Load event using an HtmlLink object:
HtmlLink link = new HtmlLink();
            link.Href = “http://www.murrayhilltech.com/images/LogoColorNoText.jpg”;
            link.Attributes["rel"] = "image_src";
            Page.Header.Controls.Add(link);
Creating these elements dynamically in the code-behind file allows us to add them to the head element of the Master Page without ever actually modifying the Master Page. You can use this same method for pages and/or sites that don’t make use of Master Pages.

Putting it all together

The complete listing for the code-behind file is shown below. The only other change we made was to add that asp:Label control to the aspx file. Here’s the code behind file:
using System;
using System.Web.UI; using System.Web.UI.HtmlControls; using System.Net.Mail; namespace MHT_Web_Site { public partial class MyPage : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { try { labelSteps_1_2.Text = "<a name=\"fb_share\" type=\"button\"></a>" + "<script " + "src=\"http://static.ak.fbcdn.net/connect.php/js/FB.Share\" " + "type=\"text/javascript\"></script>"; HtmlMeta tag = new HtmlMeta(); tag.Name = "title"; tag.Content = “This is the Title”; Page.Header.Controls.Add(tag); HtmlMeta tag = new HtmlMeta(); tag.Name = "description"; tag.Content = “This is a short summary of the page.”; Page.Header.Controls.Add(tag); HtmlLink link = new HtmlLink(); link.Href = “http://www.murrayhilltech.com/images/LogoColorNoText.jpg”; link.Attributes["rel"] = "image_src"; Page.Header.Controls.Add(link); } catch (Exception ex) { // Handle the exception } } } }
I hope that this article helps you get started integrating Facebook with ASP.NET web sites. For more information, check Facebook’s web site. The documentation there is not organized very well, but it’s there if you dig for it.
 
Trovato qui.

21 April 2011

Disabling the button while the user wait

WebForm1.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebService1.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button runat="server" ID="cmd1" Text="test..." Height="40px" Width="246px" />
        <p>
            <asp:Label runat="server" ID="lbl1" />
        </p>
    </div>
    </form>
</body>
</html>
WebForm1.aspx.vb (il trucco è la Me.cmd1.Attributes.Add alla riga 6):
Public Partial Class WebForm1
    Inherits System.Web.UI.Page

    Private Sub WebForm1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Me.cmd1.Attributes.Add("onclick", "this.value='Please wait...';this.disabled = true;" + ClientScript.GetPostBackEventReference(Me.cmd1, ""))

    End Sub

    Protected Sub cmd1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmd1.Click

        System.Threading.Thread.Sleep(1000 * 10)
        Me.lbl1.Text = Date.Now.ToString

    End Sub

End Class

Trovato qui.

19 April 2011

web.config: abilitare solo un utente

<!--<location path="AreaRiservata">-->
<location>
    <system.web>
        <authorization>
            <allow users="webmaster"/>
            <deny users="*"/>
        </authorization>
    </system.web>
</location>
Nota: i permessi sono letti in sequenza (nell’esempio: prima allow e poi deny).