Search Chirayu Software Solutions Blog

Wednesday, December 11, 2013

route command in windows

1) To List all the routes in your PC.

route print

2) To Add a route

route add -p 172.16.0.0 mask 255.255.0.0 10.25.4.1

172.16.0.0 is the destination network.
10.25.4.1 is your gateway.

3) To Delete an old route.

route delete 172.16.0.0


Tuesday, December 3, 2013

Write to Event Log in Windows PC using C# .Net

using System;
using System.Diagnostics;

namespace WriteToAnEventLog_csharp
{
 /// Summary description for Class1.
 class Class1
 {
  static void Main(string[] args)
  {
   string sSource;
   string sLog;
   string sEvent;

   sSource = "dotNET Sample App";
   sLog = "Application";
   sEvent = "Sample Event";

   if (!EventLog.SourceExists(sSource))
    EventLog.CreateEventSource(sSource,sLog);

   EventLog.WriteEntry(sSource,sEvent);
   EventLog.WriteEntry(sSource, sEvent,
    EventLogEntryType.Warning, 234);
  }
 }
}

Get Month Name from Date in Sql Query

select datename(month, S0.OrderDateTime)

Friday, November 22, 2013

Port Forwarding in Windows Server 2008

netsh interface portproxy add v4tov4 listenport=7777 listenaddress=192.168.1.36 connectport=7777 connectaddress=172.16.0.1
netsh interface portproxy add v4tov4 listenport=7013 listenaddress=192.168.1.36 connectport=7013 connectaddress=172.16.0.1

Wednesday, October 9, 2013

Launch your app to App Store of Apple iPhone

Steps to Upload App to App Store of Apple

1) Register at https://developer.apple.com/
2) Goto iOS Dev Center. https://developer.apple.com/devcenter/ios/index.action
3) Click on Certificates , Identifiers and Profiles.
4) Create Developer and Distribution Certificates.
5) Create App ID for your App.
6) Register your device used for development in this site.
7) Create provisioning profile for Development and Distribution which can be used to test the app in your device before uploading to App Store.
8) After proper testing of your app we can now upload to App Store.
9) Login to itunesconnect.apple.com
10) Click on "Add New App".
11) Fill in all the details and upload all the icons and screen shots.
12) Once the status is  Waiting For Upload.
13) Download the Application Loader from  https://itunesconnect.apple.com/apploader/ApplicationLoader_2.8.dmg
14) Upload the distribution version of the ipa using this app.


Exit a windows C# application

Application.Exit()

Solve Windows PPTP VPN Problems

If vpn client cannot connect to server try following steps :

Disable Modem firewall
Telnet server at port 1723 and check if port is accessible
Check internet speed at www.speedtest.net
Create a new vpn connection with optional encryption.

Saturday, September 28, 2013

Yes or No confirm box using jQuery

$('<div></div>').appendTo('body')
                    .html('<div><h6>Are you sure?</h6></div>')
                    .dialog({
                        modal: true, title: 'Delete message', zIndex: 10000, autoOpen: true,
                        width: 'auto', resizable: false,
                        buttons: {
                            Yes: function () {
                                // $(obj).removeAttr('onclick');                                
                                // $(obj).parents('.Parent').remove();

                                $(this).dialog("close");
                            },
                            No: function () {
                                $(this).dialog("close");
                            }
                        },
                        close: function (event, ui) {
                            $(this).remove();
                        }
                    });

NewLine in C#

Program that uses Environment.NewLine: C#

using System;

class Program
{
    static void Main()
    {
 //
 // Use string concat to combine two literals
 // with the newline constant.
 //
 string s = "First line" +
     Environment.NewLine +
     "Second line";
 Console.Write(s);
 Console.Read();
    }
}

Output

First line
Second line

convert dataset into csv file

Code Snippet
Dim str As New StringBuilder
For Each dr As DataRow In Me.NorthwindDataSet.Customers
     For Each field As Object In dr.ItemArray
     str.Append(field.ToString & ",")
     Next
     str.Replace(",", vbNewLine, str.Length - 1, 1)
Next

Try
     My.Computer.FileSystem.WriteAllText("C:\temp\testcsv.csv", str.ToString, False)
Catch ex As Exception
     MessageBox.Show("Write Error")

End Try

Thursday, September 26, 2013

check if a program is already running in c#

 if (System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)).Count() > 1)
            { 
                //application is already running
                MessageBox.Show("Cannot start,  please close it before starting again");
                System.Diagnostics.Process.GetCurrentProcess().Kill();

            }

run an external program in c#

using System.Diagnostics;

class Program
{
    static void Main()
    {
 //
 // Use Process.Start here.
 //
 Process.Start("C:\\");
    }
}

Getting Date only from a DateTime Object

DateTime date1 = new DateTime(2008, 6, 1, 7, 47, 0);
Console.WriteLine(date1.ToString());

// Get date-only portion of date, without its time.
DateTime dateOnly = date1.Date;
// Display date using short date string.
Console.WriteLine(dateOnly.ToString("d"));
// Display date using 24-hour clock.
Console.WriteLine(dateOnly.ToString("g"));
Console.WriteLine(dateOnly.ToString("MM/dd/yyyy HH:mm"));   
// The example displays the following output to the console: 
//       6/1/2008 7:47:00 AM 
//       6/1/2008 
//       6/1/2008 12:00 AM 
//       06/01/2008 00:00

How to identify if a string is a number?

This will return true if input is all numbers. Don't know if it's any better than TryParse, but it will work.
Regex.IsMatch(input, @"^\d+$")
If you just want to know if it has one or more numbers mixed in with characters, leave off the ^ + and$.
Regex.IsMatch(input, @"\d")
Edit: Actually I think it is better than TryParse because a very long string could potentially overflow TryParse.

Wednesday, April 3, 2013

Insert record in database using stored procedure in asp.net

CREATE PROCEDURE [dbo].[AddUser]
(
@FName varchar(50),
@LName varchar(50),
@DateOfBirth datetime,
@City varchar(50),
@State varchar(50)
)
AS
BEGIN

SET NOCOUNT ON;
INSERT INTO UserDetails (FName, LName, DateOfBirth, City, State)
VALUES (@FName, @LName, @DateOfBirth, @City, @State)
END


C# code

 String ConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;  
 SqlConnection con = new SqlConnection(ConnString);  
 SqlCommand cmd = new SqlCommand();  
 cmd.CommandType = CommandType.StoredProcedure;  
 cmd.CommandText = "AddUser";  
 cmd.Parameters.Add("@FName",SqlDbType.VarChar).Value = txtFName.Text.Trim();  
 cmd.Parameters.Add("@LName", SqlDbType.VarChar).Value = txtLName.Text.Trim();  
 cmd.Parameters.Add("@DateOfBirth", SqlDbType.DateTime).Value = txtDOB.Text.Trim();  
 cmd.Parameters.Add("@City", SqlDbType.VarChar).Value = txtCity.Text.Trim();  
 cmd.Parameters.Add("@State", SqlDbType.VarChar).Value = txtState.Text.Trim();  
 cmd.Connection = con;  
 try  
 {  
      con.Open();  
      cmd.ExecuteNonQuery();  
      lblMessage.Text = "Record inserted successfully";  
 }  
 catch (Exception ex)  
 {  
      throw ex;  
 }  
 finally  
 {  
      con.Close();  
      con.Dispose();  
 }  

Wednesday, February 20, 2013

Wednesday, January 30, 2013

wcf application


Creating simple application using WCF

First open Visual Studio and click file --> Select New --> Website Under that select WCF Service and give name for WCF Service and click OK 



Once you created application you will get default class files including Service.cs and IService.cs



Here IService.cs is an interface it does contain Service contracts and Data Contracts and Service.cs is a normal class inherited by IService where you can all the methods and other stuff.

Now open IService.cs write the following code

[ServiceContract]
public interface IService
{
[OperationContract]
string SampleMethod(string Name);
}

After that open Service.cs class file and write the following code 

public class Service : IService
{
public string SampleMethod(string Name)
{
return "First WCF Sample Program " + Name;
}
}


Here we are using basicHttpBinding for that our web.config file system.serviceModel code should be like this and I hope no need to write any code because this code already exists in your web.config file insystem.serviceModel

<system.serviceModel>
<services>
<service name="Service" behaviorConfiguration="ServiceBehavior">
<!-- Service Endpoints -->
<endpoint address="" binding="wsHttpBinding" contract="IService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>

Our WCF service ready to use with basicHttpBinding. Now we can call this WCF Service method console applications

After completion of WCF service creation publish or deploy your WCF Service in your system. If you don’t’ have idea on deploy tell me

After completion of deploy webservice now we can see how to use WCF Service in our console application

Calling WCF Service using Console Application

To call WCF service we have many ways like using console app, windows app and web app but here I am going for console application.

Create new console app from visual studio select project type as console application gives some name as you like.



After Creation Console application now we need to add WCF reference to our console application for that right click on your windows application and select Add Service Reference


Now one wizard will open in that give your WCF service link and click Go after add your service click OK button.


After completion of adding WCF Service write the following code in Program.cs class file Main method

static void Main(string[] args)
{
ServiceReference1.ServiceClient objService = new ServiceClient();
Console.WriteLine("Please Enter your Name");
string Message = objService.SampleMethod(Console.ReadLine());
Console.WriteLine(Message);
Console.ReadLine();
}
After that open your app.config file and check your endpoint connection for WCF Service reference that should be like this

<endpoint address=" http://localhost/WCFServiceSample/Service.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService"
contract="ServiceReference1.IService" name="WSHttpBinding_IService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
Now everything is ready run your application that output should be like this