Check whether first character in a string is capital or not

In this tutorial we will learn how to check whether first character in a string is capital or not. It’s pretty simple and don’t required any professional coding. Let’s have a look how to do so.
 
string mystring = "Adeel";

if (mystring[0].ToString() == mystring[0].ToString().ToUpper())
{
    Response.Write("First character is capital");
}
else
{
    Response.Write("First character is not capital");
}

So that’s it, this is the proper and simple way.

Happy Coding!!!

Read more...

Make first character of a string upper case in asp.net

Couple of days ago I got requirement of make first character of a string upper case in asp.net. I found but unable to get any built-in function available in .net so after some sort of coding, I develop my own function.
 
public static string MakeFirstCharUpper(string inputstring)
{
    if (String.IsNullOrEmpty(inputstring))
        throw new ArgumentException("ARGH!");
    return inputstring.First().ToString().ToUpper() + String.Join("",inputstring.ToLower().Trim().Skip(1));
}

So that’s it. Just you have to call this function and you will get desired output.

Happy Coding!!!

Read more...

Image printing problem in google chrome


In this article we will look how to fix the image printing problem in Google chrome. Most of the developers complaint that there code snippet for printing content of any div works well in all browsers except chrome, they can see images being printed in all browsers but in Google chrome neither images shown in print preview nor printed. So for Google chrome the workaround is pretty simple, just you have to add the <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\> and that's it. How? Let’s have a look

Image printing problem in Google chrome


        function printcontent() {
            var docType = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"  \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
            var disp_setting = "toolbar=yes,location=no,directories=yes,menubar=yes,";
            disp_setting += "scrollbars=yes,width=800, height=800, left=50, top=25,_blank";
            if (navigator.appName != "Microsoft Internet Explorer")
                disp_setting = "";

            var content_vlue = document.getElementById("divContent").innerHTML;
            var docprint = window.open("", "", disp_setting);
            docprint.document.open();

            docprint.document.write(docType);
            docprint.document.write('<head><title></title>');

            docprint.document.write('</head><body style="padding:0;margin-top:0 !important;margin-bottom:0!important;"   onLoad="self.print();self.close();">');

            docprint.document.write(content_vlue);
            docprint.document.write('</body></html>');
            //document.write(doct + divContent.innerHTML);
            docprint.document.close();
            docprint.focus();
        }

<div id="divContent">
        <table width="100%" cellpadding="2" cellspacing="2">
            <tr>
                <td>
                    <img src="img/web_logo_new.jpg" alt="logo" /></td>
                <td>Some content will come here </td>
            </tr>

        </table>
    </div>
    <input type="button" value="Print" onclick="printcontent();" />

So that's it. Hopefully it will fix your problem of printing images in Google chrome.
Read more...

Difference between Response.Redirect() and Response.RedirectPermanent()

In this asp.net tutorial we will learn the difference between Response.Redirect() and Response.RedirectPermanent(). Microsoft has introduced Response.RedirectPermanent() method in .net 4.0 version. The main objective of this method is to have permanent response redirection to the Search Engines.

Basically Response.RedirectParmanent() is an extension function introduced in .NET 4.0. The main aim of it is to indicate the Response Code to the Search Engine that the page has been moved permanently.

Response.Redirect() is also called 302 temporary redirect. The 302 Temporary redirects are also as they sound; temporary, in which you are telling the search engines to read and use the content of the new page, but to keep checking the original URL first as it will ultimately be reestablished. The Response.Redirect() generates Response code as 302 (Temporary Redirection). If you use the Response.Redirect() to redirect from Page A to Page B, search engines will keep Page A in their index/cache/database since the Response.Redirect() indicates a temporary redirect.

Response.RedirectPermanent() is also called 301 permanent redirect. The 301 permanent redirects are also as they sound; permanently redirects from an old URL to a new one. It also tells the search engines that the old location is to be removed from their index and replaced with the new location. Using 301 redirect is the most search engine friendly way to redirect traffic and search engines. The Response.RedirectParmanent() returns 301 (Permanent Redirection). If you use the Response.RedirectPermanent() to redirect from Page A to Page B, search engines will keep Page B in their index/cache/database since the Response.RedirectPermanent() indicates a permanent redirect and include new page for better performance on search.

Note: Another method used for redirection is Server.Transfer() in which search engine is unaware of any redirection that took place (Status 200) and keep remain the link of old page in its cache/database. Search engine thinks that the old page is producing the output response of the new page.

Read more...

Text search in Stored Procedures in SQL Server 2005 and 2008

In this ms sql server tutorial we will discuss Text search in Stored Procedures in SQL Server 2005 and 2008. There are many ways to accomplish this task. Lets have a look on those methods.
Method 1:
SELECT ROUTINE_NAME, ROUTINE_DEFINITION 
FROM INFORMATION_SCHEMA.ROUTINES 
WHERE ROUTINE_DEFINITION LIKE '%FOO%' 
AND ROUTINE_TYPE='PROCEDURE'
Method 2:
SELECT OBJECT_NAME(ID) 
FROM SYSCOMMENTS 
WHERE [TEXT] LIKE '%FOO%' 
AND OBJECTPROPERTY(ID, 'ISPROCEDURE') = 1 
GROUP BY OBJECT_NAME(ID)
Method 3:
SELECT OBJECT_NAME(object_id)
FROM sys.sql_modules
WHERE OBJECTPROPERTY(object_id, 'IsProcedure') = 1
AND definition LIKE '%FOO%' 

Remember routine_definition is cropped at 4000 chars if you have a long stored procedure. sys.sql_modules doesn't have such restriction.

So that's it. Hopefully you will find this tutorial very handy.
Read more...