Tuesday, May 18, 2010

Check If User Name Exists Using AJAX And C#

Check If User Name Exists Using AJAX And C#

check folder / directory is exist or not...


check folder / directory is exist or not...


bool exists = System.IO.Directory.Exists(@"c:\myPath");

Monday, May 3, 2010

Split a path into a string[] in C# .net




using System.Text.RegularExpressions;

string inputString = @"C:\somedir\somefile.txt";
string[] parts = Regex.Split(inputString,@"\\");
foreach (string s in parts)
{
// process the strings
}

Answer

s[0]=C:
s[1]= somedir;
s[2]=somefile.txt

Saturday, May 1, 2010

Add/Change Page Meta tags dynamically in asp.net using C#.

Meta tags are very much important for you web page, search engine use Meta tags to index you site. So some time we need to change meta tags dynamically in case of dynamic pages in asp.net.

Create a web application in c#

Drag a button and one textbox on the form

Then write code on form load event

C#

protected void Page_Load(object sender, EventArgs e)

{

HtmlHead headTag = (HtmlHead)this.Header;

// Set the page title

headTag.Title = "Title of Page";

// Add a Description meta tag

HtmlMeta PagemetaTag = new HtmlMeta();

PagemetaTag.Name = "Description";

PagemetaTag.Content = "Customized Description tag of the page";

headTag.Controls.Add(PagemetaTag);

// Add a Keywords meta tag

PagemetaTag = new HtmlMeta();

PagemetaTag.Name = "Keywords";

PagemetaTag.Content = "Customized Keyword tag of the page";

headTag.Controls.Add(PagemetaTag);

}

VB

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

Dim headTag As HtmlHead = CType(Me.Header, HtmlHead)

' Set the page title

headTag.Title = "Title of Page"

' Add a Description meta tag

Dim PagemetaTag As HtmlMeta = New HtmlMeta()

PagemetaTag.Name = "Description"

PagemetaTag.Content = "Customized Description tag of the page"

headTag.Controls.Add(PagemetaTag)

' Add a Keywords meta tag

PagemetaTag = New HtmlMeta()

PagemetaTag.Name = "Keywords"

PagemetaTag.Content = "Customized Keyword tag of the page"

headTag.Controls.Add(PagemetaTag)

End Sub

This is the simple code to change meta tags of your page dynamically.