Saturday, November 26, 2011

Reopen the Last Browsing Session in Firefox

Mozilla Firefox offers tabbed browsing, the ability to open several Web pages in a single instance of Firefox, each page opening in a new tab. One convenient feature available in Firefox is the ability for the browser to save opened tabs from a session then restore them when you re-open the browser. This way you can pick back up browsing wherever you left off. Additionally, you can access tabs from a previous browsing session, even if this feature is disabled, if you accidentally closed the browser before you were finished working. Recently I ran into a problem by accidentally closing window. But no worries we can restore by setting few settings in Firefox.

Setup Firefox To Automatically Restore Browsing Session

  1. Open the Firefox browser on your computer.
  2. Click on the "Firefox" option from the file menu and select "Options." A new window will open.
  3. Click on the "General" tab in the Options window.
  4. Click the "When Firefox starts" drop-down menu under the "Startup" section and select, "Show my windows and tabs from last time."
  5. Click "OK" to save your settings. Each time you close the browser Firefox saves any open tabs or windows and re-opens them automatically when you start the browser again.

Restore Tabs from Previous Browsing Session

  1. Open the Firefox browser on your computer.
  2. Click on the "Firefox" option from the file menu, select "History" then hover over "Recently Closed Tabs." A list of closed tabs from your previous browsing session will appear.
  3. Scroll down and click on one of the recently closed tabs. It will automatically open in a new tab within Firefox.
  4. Repeat Steps 2 and 3 until all tabs from your previous Firefox session appear in the browser.

Sunday, November 13, 2011

Validators Control to allow only Integers

Here are few different ways you can use native .NET validation controls to validate to allow only integers. We can do it in two ways one by using regular expression and one with compare validators

Method 1: Compare Validator
<asp:TextBox ID="NewMobileTextBox" runat="server" Width="280px" autocomplete="off"
CssClass="signuptxtbox" ></asp:TextBox>
<asp:RequiredFieldValidator ID="NewMobileRequired" runat="server" ControlToValidate="NewMobileTextBox"
CssClass="failureNotification" Display="Dynamic" ErrorMessage="New Mobile is required." ToolTip="New Mobile is required." ValidationGroup="ChangeNewMobileValidationGroup">*</asp:RequiredFieldValidator>
<asp:CompareValidator ID="NewMobileCompare" runat="server" ControlToValidate="NewMobileTextBox" CssClass="failureNotification" Display="Dynamic" Operator="DataTypeCheck" ErrorMessage="Mobile Number should be numeric only." ValidationGroup="ChangeNewMobileValidationGroup" Type="Integer">*</asp:CompareValidator>


Method 2: Regular Expression Validator

<asp:TextBox ID="NewMobileTextBox" runat="server" Width="280px" autocomplete="off"
CssClass="signuptxtbox" ></asp:TextBox><asp:RequiredFieldValidator ID="NewMobileRequired" runat="server" ControlToValidate="NewMobileTextBox"
CssClass="failureNotification" Display="Dynamic" ErrorMessage="New Mobile is required." ToolTip="New Mobile is required." ValidationGroup="ChangeNewMobileValidationGroup">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="mobileRGEX" runat="server"
ControlToValidate="NewMobileTextBox" CssClass="failureNotification"
ErrorMessage="Please Enter Only Numbers" ValidationExpression="^\d+$"
ValidationGroup="ChangeNewMobileValidationGroup"></asp:RegularExpressionValidator>

Saturday, November 12, 2011

Hot Fix For Windows 7 Start Menu Search Not Working

Sometimes in windows 7 start menu search will not work. Many blogs will tell you to edit the registry. But it is not recommended. Microsoft released the hotfix for this. Download at: http://support.microsoft.com/hotfix/KBHotfix.aspx?kbnum=977380&kbln=en-us

Wednesday, November 02, 2011

Regex validate Email address C#

This is how we can validating email address through C# using Regular Expression. Here is the sample code,

using System.Text.RegularExpressions;



public bool vaildateEmail(string useremail)
{
bool istrue = false;
Regex reNum = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
CaptureCollection cc = reNum.Match(useremail).Captures;
if (cc.Count == 1)
{
istrue = true;
}
return istrue;
}

Delete All Files using C#

For Deleting all the files first you need to get the list of file names from the specified directory (using static method Directory.Get­Files. Then delete all files from the list.
Method 1
using System.IO;

string[] filePaths = Directory.GetFiles(@"c:\Directory\");
foreach (string filePath in filePaths)
  File.Delete(filePath)

Method 2

To Delete all files using one code line, you can use Array.ForEach with combination of anonymous method.

Array.ForEach(Directory.GetFiles(@"c:\MyDirectory\"),delegate(string path) 
{ File.Delete(path); });

How to get current page Filename using C#

There are different ways to get current page filename using c#. Here are 3 methods you can use for your advantage.

Method 1
string currentPageFileName = new FileInfo(this.Request.Url.LocalPath).Name;

Method 2

string sPath = HttpContext.Current.Request.Url.AbsolutePath;
string[] strarry = sPath.Split('/');
int lengh = strarry.Length;
string sReturnPage = strarry[lengh - 1];

Method 3

string absPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
System.IO.FileInfo finfo = new System.IO.FileInfo(absPath);
string fileName = finfo.Name;

 

Out of these I like Method 1 and 3 as its straight forward. Use a per your advantage. Good luck.

C# Checking a File exists in Folder

How to get all files from a folder and compare a whether that file exists in that folder or not. Here is a sample code where you can loop through the code and check the file.

I have declared a variable to check there it exists or not.

private bool isFileExists = false;


Now I have this code to check whether file exists and based on it I’ll redirect in to that page.


string searchfolder = Server.MapPath("~") + "\\TestFolder";
DirectoryInfo Dir = new DirectoryInfo(searchfolder);
FileInfo[] FileList = Dir.GetFiles("*.aspx", SearchOption.AllDirectories);
foreach (FileInfo FI in FileList)
{
if (FI.Name == redirectPage)
{
isFileExists = true;
break;
}
}
if (isFileExists == true)
{
Response.Redirect("~/redirectPage");
}
else
{
Response.Redirect("
~/OtherRedirect.aspx");
}

Here I have search pattern as *.aspx as I need to check these files. This can be based on the files you want to check