Thursday, June 26, 2014

How to write the text file using the WPF application



Introduction

This article goes to understanding of the code of writing the text file from the c# .
Here the “ExceptionHandler” will takes the input parameter as string to what the data to write in the text file
This method “CallExceptionHandler” will work for writing the test in the file
Note:-Make Shure to Create one folder in the c drive with the name of “Log”

public void ExceptionHandler(string ExceptionMessage)
        {
            try
            {
                // string root = Directory.GetCurrentDirectory() + "\\Log";
                // if (!Directory.Exists(root))
                // {
                // Directory.CreateDirectory(root);
                // }

                string root = "C:\\Log\\";
                string path = root + "SampleTextFile" + System.DateTime.Now.ToString("ddMMyyy") + ".txt";

                CallExceptionHandler(path, ExceptionMessage);

            }
            catch (Exception)
            { }
        }
 private void CallExceptionHandler(string strPath, string strException)
        {
            FileStream fsFile = null;
            StreamWriter swWriter = null;
            try
            {
                if (File.Exists(strPath))
                {
                    fsFile = new FileStream(strPath, FileMode.Append, FileAccess.Write);
                    swWriter = new StreamWriter(fsFile);
                    swWriter.WriteLine(Environment.NewLine + DateTime.Now.ToString("dd-MMM-yyyy hh:mm:ss") + "-----------" + Environment.NewLine);

                    swWriter.WriteLine(strException);
                }
                else
                {
                    fsFile = new FileStream(strPath, FileMode.Create, FileAccess.Write);
                    swWriter = new StreamWriter(fsFile);
                    swWriter.WriteLine(strException);
                }
                swWriter.Flush();

            }
            catch (Exception)
            {
            }
            finally
            {
                swWriter.Close(); fsFile.Close(); swWriter.Dispose(); fsFile.Dispose();
            }
        }


Read More »

Wednesday, June 25, 2014

Color conventions in c# of to and fro conversion(HTML to C# and C# to HTML)

Introduction

In this article I explain how to convert the HTML colors to the c# colors because in c# we have only limited number of colors like example red, green, blue etc…. If you want to display the color some shaded color and RGB color mixing process you can use this methods to overcome this functionalists

Write the below code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;



Read More »

Tuesday, June 24, 2014

Sending Mail from Asp.Net c# with Attachment

Introduction

This post will explain you how to sending the mail from the asp.net along with file attachment

Note:- You can send even though you company having Gmail access

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;


Read More »

Sending Mail from Asp.Net c#

Introduction

This post will explain you how to sending the mail from the asp.net

Note:- You can send even though you company having Gmail access 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;






namespace SampleTestingCodes
{
    public partial class SendingMailFromAsp : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            SendMail();
        }
        protected void SendMail()
        {
            // Gmail Address from where you send the mail
            var fromAddress = "gmail@gmail.com";
            // any address where the email will be sending
            var toAddress = txtemailid.Text.ToString();
            //Password of your gmail address
            const string fromPassword = "*****************************";
            // Passing the values and make a email formate to display
            string subject = txtsubject.Text.ToString();
            string body = "From: " + txtyourname.Text + "\n";
            body += "Email: " + txtemailid.Text + "\n";
            body += "Subject: " + txtsubject.Text + "\n";
            body += "Question: \n" + txtbody.Text + "\n";
            // smtp settings
            var smtp = new System.Net.Mail.SmtpClient();
            {
                smtp.Host = "smtp.gmail.com";
                smtp.Port = 587;
                smtp.EnableSsl = true;
                smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
                smtp.Timeout = 20000;
            }
                  using (var message = new MailMessage(fromAddress, toAddress)
                {
                    Subject = subject,
                    IsBodyHtml = true,
                    Body = body


                })
                {
                    smtp.Send(message);
                }
                // Passing values to smtp object
                //smtp.Send(fromAddress, toAddress, subject, body);
        }
    }
}



Out put will look like
From: lokehs
Email: lannam@technobrainltd.com
Subject: hi
Question:
gg



Read More »

Wednesday, June 18, 2014

Examples of LINQ and LABDMA expression examples, functions and usages for collection types

Write the below code and execute

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LinqAndLambdaExpressions.aspx.cs"
    Inherits="SampleTestingCodes.LinqAndLambdaExpressions" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>

Read More »

Sunday, June 15, 2014

How to bind the Asp.Net grid with selected data using Lambda Expressions

Write the bellow code for and execute

In Design Side

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LinqAndLambdaExpressions.aspx.cs"
    Inherits="SampleTestingCodes.LinqAndLambdaExpressions" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>

Read More »

Wednesday, June 11, 2014

Find the 1’s Compliment for the binary number in the SQL SERVER

Example :-1

1’s Complete Example

Declare @MainChar Varchar(Max)='0101010101'
set @MainChar=replace(replace(replace(@MainChar,'1','a'),'0','1'),'a','0')
select @MainChar

output
1010101010


Example :-2

1’s Complete Example

Declare @MainChar Varchar(Max)='000000'
set @MainChar=replace(replace(replace(@MainChar,'1','a'),'0','1'),'a','0')
select @MainChar

output
111111

Example :-3 

1’s Complete Example

Declare @MainChar Varchar(Max)='11111'
set @MainChar=replace(replace(replace(@MainChar,'1','a'),'0','1'),'a','0')
select @MainChar

output

00000
Read More »

Find the 2’s Compliment for the binary number in the SQL SERVER

2’s Complete Example

Declare @MainChar Varchar(Max),@ReveL Varchar(Max),@ReveR Varchar(Max)
set @MainChar='0010010010'
if(len(replace(@MainChar,'0',''))>0)
begin
set @MainChar=replace(replace(replace(@MainChar,'1','a'),'0','1'),'a','0')
set @MainChar=REVERSE(@MainChar)
set @ReveL=replace(replace(replace(SUBSTRING(@MainChar,1,CHARINDEX('0', @MainChar)),'1','a'),'0','1'),'a','0');
set @ReveR=SUBSTRING(@MainChar,CHARINDEX('0', @MainChar)+1,Len(@MainChar)-(CHARINDEX('0', @MainChar)))
select REVERSE(@ReveL+@ReveR)
end
else
select @MainChar

output

1111011110
Read More »

Convert Textbox in the Custom Language Transliteration in ASP.Net

Create on sample we page and write this code below


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LanguageTextBox.aspx.cs"
    Inherits="SampleTestingCodes.LanguageTextBox" ClientIDMode="Static" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
        google.load("elements", "1", {
            packages: "transliteration"
        });
        var control = null;
        function GetConvertText() {
            var options = {
                sourceLanguage: google.elements.transliteration.LanguageCode.ENGLISH,
                destinationLanguage: [google.elements.transliteration.LanguageCode.TELUGU],
                shortcutKey: 'ctrl+g',
                transliterationEnabled: true
            };
            // Create an instance on TransliterationControl with the required options.
            control = new google.elements.transliteration.TransliterationControl(options);
            control.makeTransliteratable(['TextBox1']);
        }
       
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    </div>
    <asp:TextBox ID="TextBox1" runat="server" onKeyup="GetConvertText();"></asp:TextBox>
    </form>
</body>
</html>




Happy coding  JJJJJJJJJJJJJJJJJJJJJJJ
Read More »