Archive

Archive for the ‘Visual Studio 2008’ Category

Bypass specific IP from rendering google analytics code

January 13, 2011 Leave a comment

To bypass specific IP from rendering google analytics code, follow the following steps.

  1. List the IP which you wants to bypass from rendering into your web application, and add in web.config file

    e.g. <add key=ByPassUrl value=101.101.101.100/>

  2. Create a Usercontrol and named “GoogleAnalytics.ascx” replace your google analytics code with “<google analytics code here>“.

    <%@Control Language=”C#” AutoEventWireup=”true” CodeFile=”GoogleAnalytics.ascx.cs”
    Inherits=”Include_GoogleAnalytics”%>

    <script type=”text/javascript”>

    <% if (ConfigurationManager.AppSettings[“showGoogleAnalytics”] == “True”) {%>

    <% if (!strByPassUrl.Contains(requestUrl)) {%>

    var _gaq = _gaq || [];

    _gaq.push([‘_setAccount’, <google analytics code here>]);

    _gaq.push([‘_trackPageview’]);

    (function() {

    var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;

    ga.src = (https: == document.location.protocol ? https://ssl : http://www) + ‘.google-analytics.com/ga.js’;

    var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);

    })();

    <% } %>

    <% } %>

    </script>

     

  3. Declare following 2 public variable in “GoogleAnalytics.ascx.cs” file

    public string requestUrl = HttpContext.Current.Request.UserHostAddress.ToString();
    public
    string strByPassUrl = clsCommon.value(“ByPassUrl”);

  4. Add “GoogleAnalytics” user control in master page of the application within <Head></Head> tag.

    <head runat=”server”>

    <uc2:GoogleAnalytics ID=”GoogleAnalytics1″ runat=”server”/>

    </head>

Note :- 1) Before Copying Google analytics code verify with google analytics script, provided in google analytics account.

2) check if “showGoogleAnalytics” key is present in web.config file.

Advertisements

Sending HTML Mail

MailMessage mail = new MailMessage(FromEmail, Toemail);
mail.Bcc.Add(AdminEmail);

mail.Subject = “Subject goes here”;

string strBody = “”;
strBody = “Message Body”;

mail.IsBodyHtml = true;
mail.Body = strBody;

SmtpClient client = new SmtpClient();
client.Host = SMTPServer;
client.Port =SMTPPort;

System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential(SMTPUser, SMTPPassword);
client.UseDefaultCredentials = false;
client.Credentials = basicAuthenticationInfo;

try
{
client.Send(mail);
}
catch (Exception ex)
{

}

How to Configure Source Control for Visual Studio 2008

When you have first installed Microsoft Visual Studio 2008 and Micrsoft Visual SourceSafe 2005, there is not initially a configured relationship between the two applications.
Source Control is not a menu item at this state until you configure the Source Control plug-in by using the Options dialog screen.

You can open the Options dialog screen by selecting Tools in the main menu then selecting Options submenu item. Drill down to the Source Control and Plug-in Selection in the options treeview.
There is a drop down list which lists available Source Control options and applications and an option for indicating not to use any of the source control software. In order to use Microsoft Visual SourceSafe 2005, you can select “Microsoft Visual SourceSafe” in the available source control plug-in combobox.

plug-in-selection for Visual studio 2008

plug-in-selection for Visual studio 2008

If you select Visual SourceSafe plug-in two more branches will appear in the options treeview below the Source Control, “Environment” and “Plug-in Settings”.

Export Grid Data to Excel

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.AddHeader(“content-disposition”, “attachment;
        filename=FileName.xls”);
        Response.Charset = “”;
        Response.ContentType = “application/vnd.xls”;
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite =
        new HtmlTextWriter(stringWrite);
        GridView1.RenderControl(htmlWrite);
        Response.Write(stringWrite.ToString());
        Response.End();

    }

Thanks