Tuesday, July 17, 2018

How to restrict someone from copying content from my website ?

 Use this script in your web site:

<script type="text/javascript">
    function disableselect(e) {
        return false;
    }
    function reEnable() {
        return true;
    }
    document.onselectstart = new Function("return false");
    if (window.sidebar) {
        document.onmousedown = disableselect;
        document.onclick = reEnable;
    }
</script>
<script type="text/javascript">

    var isCtrl = false;
    document.onkeyup = function (e) {
        if (e.which == 17)
            isCtrl = false;
    }
    document.onkeydown = function (e) {
        if (e.which == 17)
            isCtrl = true;
        if (((e.which == 85) || (e.which == 67) || (e.which == 83)) && isCtrl == true) {
            return false;
        }
    }
    document.oncontextmenu = RightMouseDown;
    document.onmousedown = mouseDown;
    function mouseDown(e) {
        if (e.which == 3) {
            alert("Unauthorized copying of content not allowed. We will take legal action and file DMCA complaint against any online website or news agency that is found copying our content.");
        }
    }
    function RightMouseDown() {
        return false;
    }
</script>

Monday, July 16, 2018

How to add Month or Day with a Date ?

//.....Add 1 month From Selected Date

AddMonthToDate: function (selectedDate, month) {
     
        var date = new Date(selectedDate);
        var currentDate = date.getDate();
        date.setDate(month);
        date.setMonth(date.getMonth() + month);
        var daysInMonth = new Date(date.getYear(), date.getMonth() + month, 0).getDate();
        date.setDate(Math.min(currentDate, daysInMonth));
        return date;
    },
  

//...Add 30 Days From Selected Date

    AddDaysToDate: function (selectedDate, days) {
   
        var x = selectedDate.getDate();
        var m1 = selectedDate.getMonth();
        selectedDate.setDate(selectedDate.getDate() + days);
        var m2 = selectedDate.getMonth();
        if (m1 == m2) {
            selectedDate.setDate(selectedDate.getDate() + 1);
        }
        return new Date(selectedDate);
    }

How to write a Log File in C# ?

 private static void WriteLog(string message)
        {
            try
            {
                var date = DateTime.Now;
                var day = date.Day.ToString();
                var month = date.Month.ToString();
                var year = date.Year.ToString();
                var fileName = day +"_"+ month +"_"+ year;
                string fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "LogFile_Log");
                if (!Directory.Exists(fullPath))
                {
                    Directory.CreateDirectory(fullPath);
                }

                var streamWriter = new StreamWriter(Path.Combine(fullPath,fileName + ".txt"), true);


                streamWriter.WriteLine(message.Trim());
                streamWriter.Flush();
                streamWriter.Close();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }

How to validate your Email Address in C# ?

bool IsValidEmail(string email)
{
    try {
        var mail = new System.Net.Mail.MailAddress(email);
        return true;
    }
    catch {
        return false;
    }
}

How to get Host Name of your PC in C#?

string ip = Request.UserHostName;

var hostName= GetLocalHostName(ip )

public string GetLocalHostName(string ip)
        {
            IPAddress ipadd = System.Net.IPAddress.Parse(ip);
            IPHostEntry hostName = Dns.GetHostEntry(ipadd);
            var list = hostName.HostName.ToString().Split('.').ToList();
            var host = list.First();
            return host;
        }

How to get date different between two date in jquery?

get date different between two date in jquery:
==================================================================
        var oneDay = 24 * 60 * 60 * 1000;
        var entryDate = kendo.parseDate(obj.RowDate, "d");
        var today = kendo.parseDate(new Date(), "d");
        var diffDays = Math.round(Math.abs((today.getTime() - entryDate.getTime()) / (oneDay)));

How to change logical file name of a Database in SQL ?


 --change log file name
ALTER DATABASE [TESTDB] MODIFY FILE (NAME = TESTDB_log,
NEWNAME = TESTDBNEW_log);


--change data file name
ALTER DATABASE [TESTDB] MODIFY FILE (NAME = TESTDB_DATA,
NEWNAME = TESTDBNEW_DATA);