I am going to demonstrate here how to add log4net in .net MVC and keeping the configuration file separate and making the log file with everyday’s date.Read More »
Unit Testing of File uploading in MVC
Ways to write unit test code for File upload on Controllers:
For file upload related testing we need to Mock HTTPContext, HTTPContext.Server and HttpPostedFileBase. These classes handle the file uploading and saving.
We have to add a nugget package named Moq (https://www.nuget.org/packages/moq/) which will help us mocking the above classes. Moq source in Git: https://github.com/moq/moq4Read More »
Recursion with Common Table Expression in T-SQL
Generally for recursion we use Cursor in T-SQL. But Cursor is a kind of for loop which execute expression one by one until the end of the dataset or table or vew for which Cursor is defined. T-SQL is providing a different and unique technique called “Common Table Expression” or CTE which can do recursion by referencing itself. As CTE can recurrently call itself with select statement depending on the type of join operation, it is a bulk operation for recursion which can make your select query operation incredibly faster.
Take automatic backup of all database in the server
I am a lazy guy to do backup of all database of a server manually in each month. So, I find out a solution. Just I make a cursor on database list from “master.dbo.sysdatabases” table and run the backup command inside the cursor: BACKUP DATABASE @name TO DISK = @fileName Read More »
dynamic sql command
Sometimes you may need to write dynamic SQL command where you can change table name or other properties which can’t be pass by parameter. The EXEC command in T-SQL can make it possible. What you have to do is to make the sql syntax into a string as bellowsRead More »
Delete rows according to rows of different table
Syntax: delete rows according to data of different table
DELETE Table1 FROM Table1 INNER JOIN Table2 ON Table1.ID = Table2.ID
SQL Update table depending on a table or view
Sometimes you may need to update a table depending on another table or a view or temporary table or even on same table. In such cases instead of using a for loop or Cursor, you can follow the bellow example of using join statement-Read More »
Send Email in ASP.net with secure SSL port 465
There are two ways to do SMTP over SSL: Explicit and Implicit. Explicit means you connect to a normal SMTP port (usually 25 or 587) in plaintext, then issue the “starttls” command to switch to SSL-mode. Implicit means you connect to a port that expects everything to be SSL (usually 465).
Asp.net use “System.Net.Mail.SmtpClient()” to send Email. The main problem is SmtpClient does not support implicit SSL connections, but does support explicit connections (System.Net.Mail with SSL to authenticate against port 465). So, if the mail server(SMTP) do not support Explicit connection, it fails to send email and show messages like “Connection timeout“, “The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available” etc.Read More »
Detect language from content in website with javascript
Suppose you have some content of your English language site is in Arabic or any other language who’s direction is right to left. Your client wants to see that content in correct direction. In this cases you have detect the language of the content.
We can do the language detection dynamically in client side with javascript and Google Cloud Translation API.Read More »