Tuesday, September 7, 2010

मंगल भवन अमंगल हारी - राम सिया राम सिया राम जय जय राम ,Mangal Bhavan Amangal Haari , Lyrics

मंगल भवन अमंगल हारी
द्रवहु सुदसरथ अचर बिहारी
राम सिया राम सिया राम जय जय राम - २

हो, होइहै वही जो राम रचि राखा
को करे तरफ़ बढ़ाए साखा

हो, धीरज धरम मित्र अरु नारी
आपद काल परखिये चारी

हो, जेहिके जेहि पर सत्य सनेहू
सो तेहि मिलय न कछु सन्देहू

हो, जाकी रही भावना जैसी
रघु मूरति देखी तिन तैसी

रघुकुल रीत सदा चली आई
प्राण जाए पर वचन न जाई
राम सिया राम सिया राम जय जय राम

हो, हरि अनन्त हरि कथा अनन्ता
कहहि सुनहि बहुविधि सब संता

Hare Ram !!
हरे राम ||

Thursday, August 12, 2010

System.Windows.Xps.Packaging - Reach Framework => Add reference DLL

Hello Guys,

If you need to use XpsDocument class in your project, you must add reference to System.Windows.Xps.Packaging namespace. It is defined in the ReachFramework.

In order to add reference to ReachFramework, you right click on Add Reference on the project name in Solution Explorer. On the .NET Framework, select ReachFramework and other assemblies from the list and click OK button




Hope you find it useful.
Thanks,
Nitin Sharma
.


Tuesday, August 10, 2010

Database Back up using SQL Query

Hi All,
Today i came through a problem where in i have to take Back up of the SQL server database .
It is a simple query :

BACKUP DATABASE TestDB TO DISK='D:\MyDatabase.bak' with FORMAT


Where
"TESTDB" => Your Database Name
"D:\" => Any local Hard Drive C,D,E,F or any;
"MyDataBase" => Any name by which you want to take Back up.


Thanks,
Nitin Sharma

Ancient Saying - Pehla Sukh Nirogi Kaya . . . .

Below is one of the ancient saying that i would like to share with you.It is well said by our ancestors & has a deeper meaning in terms of living life.Our life is complete then.

PEHLA SUKH NIROGI KAYA
DOOSRA SUKH GHAR MEIN HO MAYA
TEESRA SUKH KULWANTI NARI
CHAUTHA SUKH PUTRA AGYAKARI

You have bliss if you have a healthy body
You have bliss if you have a home filled with wealth
You have bliss if you have a faithful wife
You have bliss if you have an obedient son.


Thanks,
Have a Nice Day.!
Nitin Sharma

Monday, June 14, 2010

IM Chat with God : i like it much

Did You Call Me?
===========

God: Hello. Did you call me?
Me: Called you? No... Who is this?

God: This is GOD. I heard your prayers.
So, I thought I will chat.
Me: I do pray. Just makes me feel good.
I am actually busy now.

God: What are you busy at? Ants are busy too.
Me: Don't know. But, I can't find free time.
Life has become hectic. It's rush hour all the time.

God: Sure. Activity gets you busy.
Productivity gets you results.
Activity consumes time. Productivity frees it.
Me: I understand. Yet, I still can't figure out. By the way,
I was not expecting YOU to call me on instant messaging chat

God: I wanted to solve your fight for time, by giving you some
clarity. In this internet era, I wanted to reach you
through the way in which you would understand.

Me: Tell me, why has life become complicated now?
God: Stop analyzing life. Just live it. Analysis makes it
complicated.

Me: Why are we constantly unhappy?
God: Your today is the tomorrow that you worried about
yesterday. You are worrying because you are analyzing.
Worrying has become your habit. That's why you are not
happy.

Me: How can we not worry when there is so much uncertainty?
God: Uncertainty is inevitable. Worrying is optional.

Me: There is so much pain due to uncertainty.
God: Pain is inevitable - it will come. Suffering is optional,
you can choose.

Me: If suffering is optional, why do good people also suffer?
God: Diamonds cannot be polished without friction.
Gold cannot be purified without fire.
Good people go through trials, but, don't suffer.
With that experience, their life becomes better,
not bitter.

Me: You mean to say such experience is useful?
God: Yes. Experience is a hard teacher.
She gives the test first and the lessons afterwards.

Me: Still, why should we go through such tests?
Why can't we be free from problems?
God: Problems are purposeful roadblocks offering beneficial
lessons to develop strength.
Inner strength comes from struggle and endurance,
not when you are free from problems.

Me: Frankly, in the midst of so many problems,
we don't know where we are heading...
God: If you look outside, you will not know where you are going.
Look inside.
Looking outside, you dream.
Looking inside, you awaken.
Eyes provide sight. Heart provides insight.

Me: Sometimes not succeeding fast seems to hurt more than
moving in the right direction. What should I do?
God: Success is a measurement decided by others.
Satisfaction is a measurement decided by you.
Knowing the road ahead is more satisfying.
You work with the compass. Let others work with the clock.

Me: In tough times, how do you stay motivated?
God: Always look at how far you have come rather than how far
you have to go.
Always count your blessing, not what you are missing.

Me: What surprises you about people?
God: When they suffer they ask, "Why me?"
When they prosper, they never ask "Why me?"
Everyone wishes to have truth on their side.
Few want to be on the side of the truth.

Me: Sometimes, I ask, "Who am I? Why am I here?"
I can't get the answer.
God: Seek not to find who you are, but, to determine who you
want to be. Stop looking for a purpose as to why you are
here. Create it.
Life is not a process of discovery.
It's a process of creation.

Me: How can I get the best out of life?
God: Face your past without regret.
Handle your present with confidence.
Prepare for the future without fear.

Me: One last question. Sometimes, I feel my prayers are not
answered.
God: There are no unanswered prayers. At times, the answer is
"NO."

Me: Thank you for this wonderful chat.
God: Well, keep the faith and drop the fear.
Life is a mystery to solve not a problem to resolve.

Trust me.


Friday, April 9, 2010

Fetch Files with more than one extension from a Directory and Sorth them

Hi All,
There may be requirements in your project sometimes where you may fetch files of Particular extensions from a directory.
The Simple way for extension say " .docx " , the Directory search pattern works.

string[] fns = Directory.GetFiles(@"D:\Documents\", "*.docx*");

However if you want to search files of more than one type(extension), here is the way.

CODE:

var sort = from fn in fns

where fn.Contains(".jpg") || fn.Contains(".txt") || fn.Contains(".png")

orderby new FileInfo(fn).CreationTime descending

select fn;


I hope you know var keyword :p.(The anonymous types introduced in C# 3.0).

In the above example it gives the collection.

So at the end you get filtered all files from the directory/folder by just providing the extension name in file.contains() syntax like fn.Contains(".jpg")

Also note that the files can also be sorted(ascending/descending) by file Size,lastAccess,LastWrite,CreationTime.
In above example the files are sorted by CreationTime.

Thanks,
Nitin Sharma
Happy Coding

Thursday, March 18, 2010

Delete Selected item from XML Node


All,

Today i gonna share with you code related to XML file.
That is reading and reading XML files.

Following Steps will be shown:
a) First populate listbox with XML data.
b) Second select any item in the Listbox and delete that node from the XML.

Prerequisites:
Add using System.XML namespace above.
Add listbox and a Button(for Delete).
Make an XML file and store in any directory (D directory in my example).

First Below is the Sample XML file :( I have stored it in as : D:\DocumentsOrder.xml).



On Form Load write the below code:

private voidForm1_Load(object sender,EventArgs e)

{

XmlDocument xDoc = newXmlDocument();

xDoc.Load(@"D:\DocumentsOrder.xml");

for (int i = 0; i <>

{

//Add the innertext of the xml document to the listbox

listBox1.Items.AddRange(newobject[] { xDoc.DocumentElement.ChildNodes[i].InnerText });

}

}


On Delete Button Click event write the following Code:


private voidbutton5_Click(object sender,EventArgs e)

{

XmlDocument xDoc = newXmlDocument();

xDoc.Load(@"D:\DocumentsOrder.xml");

//Add the innertext of the xml document to the listbox

xDoc.DocumentElement.RemoveChild(xDoc.DocumentElement.ChildNodes[listBox1.SelectedIndex]);

FileStream WRITER = newFileStream(@"D:\DocumentsOrder.xml", FileMode.Truncate,FileAccess.Write,FileShare.ReadWrite);

xDoc.Save(WRITER);

//Close the writer filestream

WRITER.Close();

//Form1_Load(new object(), new EventArgs());

}



Thats it...Your XML Node(selected item in Listbox) is deleted.

So here is the preview:






Now Go and check your XML...
Hope the selected Node is deleted.

Regards,
Nitin Sharma

Send Outlook E mail using VB macros

All,
Below is the VB Macro code to send mail using Microsoft Outlook :

Lines mark with " ' " are commented.

Sub SendMail()

'

'This macro requires the Outlook Object library to be checked

'in the vba editor Tools > References

Dim bStarted As Boolean

Dim oOutlookApp 'As outloo

Dim oItem 'As Outlook.MailItem

On Error Resume Next

'see if Outlook is running and if so turn your attention there

Set oOutlookApp = GetObject(, "Outlook.Application")

If Err <> 0 Then 'Outlook isn't running

'So fire it up

Set oOutlookApp = CreateObject("Outlook.Application")

bStarted = True

End If

'Open a new e-mail message

Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem 'and add the detail to it

.To = "abc@yahoo.com" 'send to this address

.Subject = "This is a Test Mail using VB Macros" 'This is the message subject

.Body = "See attached document" ' This is the message body text

.Attachments.Add ActiveDocument.FullName

ActiveDocument.SaveAs strFilePath & strDate

.Send

'**********************************

'If you want to view the message before it goes

'change the line above from .Send to .Display

'Otherwise the message is sent straight to the Outbox

'and if you have Outlook set to send mail immediately,

'it will simply be Sent

'with no obvious sign that Outlook has operated.

'Apart from the copy in the Outlook Sent folder

'**********************************

End With

If bStarted Then 'If the macro started Outlook, stop it again.

oOutlookApp.Quit

End If

'Clean up

Set oItem = Nothing

Set oOutlookApp = Nothing

End Sub





Regards,

Nitin Sharma

Friday, March 12, 2010

Upload Word Document using Sharepoint Web Services


All,
Below is the sample code to add a Microsoft Word Document inside the Sharepoint Documen Library's folder.

Say i have a Document Library as CoastGuard and it has four folders : MIS,Aviation,IT and Logistics.So i need to add document in these folders using Sharepoint in built web services.

Below is the Code:

using System;

usingSystem.Collections.Generic;

using System.Configuration;

usingSystem.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Xml;

using System.IO;

using System.Collections;

using Microsoft.SharePoint;

using System.Net;

namespace Signals

{

public partial class Form1:Form

{

public Form1()

{

InitializeComponent();

}

private voidForm1_Load(objectsender,EventArgs e)

{

GetFiles();

GetFoldersList();

}

private void GetFoldersList()

{

wsLists.Lists spList =newSignals.wsLists.Lists();

spList.Credentials = System.Net.CredentialCache.DefaultCredentials;

stringspUrl=ConfigurationSettings.AppSettings["SPFolders"].ToString();

spList.Url ="http://Win08r2/Signals/_vti_bin/Lists.asmx";

XmlNode listnodes = spList.GetListItems("CoastGuard", null, null, null, null, null,null);

foreach (XmlNode nodeinlistnodes)

{

if (node.Name == "rs:data")

{

for (int i = 0; i <>

{

if (node.ChildNodes[i].Name == "z:row")

{

listView1.Items.Add(node.ChildNodes[i].Attributes["ows_LinkFilename"].Value);

}

}

}

}

}

private void GetFiles()

{

string strPath ="..\\..\\Documents";

DirectoryInfo di =newDirectoryInfo(strPath);

FileInfo[] fi = di.GetFiles();

foreach (FileInfo f in fi)

{

listView2.Items.Add(f.Name);

}

}

privatevoidbutton1_Click(objectsender,EventArgs e)

{

wsLists.Lists spList =newSignals.wsLists.Lists();

spList.Credentials = System.Net.CredentialCache.DefaultCredentials;

spList.Url ="http://Win08r2/_vti_bin/Lists.asmx";

listView1.Items[0].Selected =true;

string DocFileName = "";

foreach (ListViewItem linlistView2.SelectedItems)

{

DocFileName = l.Text.ToString();

}

if (DocFileName != "")

{

if(listView1.CheckedItems.Count > 0)

{

for (int i = 0; i <>

{

WebClient WC =newWebClient();

WC.Credentials =CredentialCache.DefaultCredentials;

WC.UploadData("http://Win08r2/signals/CoastGuard/"+ listView1.CheckedItems[i].Text + "/" + DocFileName, "PUT", StreamFile(@"..\\..\\Documents\" + DocFileName));

}

MessageBox.Show("Files moved successfully");

}

else

{

MessageBox.Show("Please Select At Least One Folder");

}

}

else

{

MessageBox.Show("Please Select a File");

}

}

private byte[] StreamFile(stringfilename)

{

FileStream fs =newFileStream(filename,FileMode.Open,FileAccess.Read);

// Create a byte array of file stream length

byte[] ImageData =newbyte[fs.Length];

//Read block of bytes from stream into the byte array

fs.Read(ImageData, 0, System.Convert.ToInt32(fs.Length));

//Close the File Stream

fs.Close();

return ImageData; //return the byte data

}

privatevoidbutton2_Click(objectsender,EventArgs e)

{

foreach (ListViewItem liinlistView1.Items)

{

li.Checked = true;

}

}

privatevoidbutton3_Click(objectsender,EventArgs e)

{

foreach (ListViewItem liinlistView1.Items)

{

li.Checked = false;

}

}

}

}

Here's the Result:

Form1 screenshot.Multiple folders can be selected,but only single file can be selected.


Document uploaded successfully..



Regards,

Nitin Sharma


Fetch Temp directory of Windows using VBA macros

Hey,
I am working on VBA Macros for a small module.I came across a need to find the temp directory path using VBA.so here it is:

Public Function GetTempDir() As String
Dim sRet As String, lngLen As Long
'create buffer
sRet = String(MAX_PATH, 0)

lngLen = GetTempPath(MAX_PATH, sRet)
If lngLen = 0 Then Err.Raise Err.LastDllError
GetTempDir = Left$(sRet, lngLen)
End Function



Access above function here as :
Sub TestMacro

Dim strFilePath As String
strFilePath = GetTempDir()
End Sub

Regards,
Nitin Sharma

Adding Images in Word Document using C#.NET

Hey,
I came across a requirement where i need to add Images in the Microsoft word document using C# code in Windows application.


I searched and wrote the code as follows but before that :

Step 1) do add reference to Microsoft Word Object Library.

Step 2) Add using Microsoft.Office.Interop.Word;
using System.IO; namespaces on top.


Code in Form1.cs:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.Word;
using System.IO;

namespace Sample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
object missing = System.Reflection.Missing.Value;
object Visible=true;
object start1 = 0;
object end1 = 0;

ApplicationClass WordApp = new ApplicationClass();
Document adoc = WordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
Range rng = adoc.Range(ref start1, ref missing);

try
{

foreach (ListViewItem Li in listView1.Items)
{

FileInfo Fi = new FileInfo(Li.Text);

rng.InlineShapes.AddPicture(Fi.ToString(), ref missing, ref missing, ref missing);

}

rng.Font.Name = "Georgia";
rng.InsertAfter("Hello World!");
object filename = @"D:\"+textBox1.Text+".docx"; //Saves in D directory


adoc.SaveAs(ref filename, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);


}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void butBrowse_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
string [] FileNames = openFileDialog1.FileNames;
foreach (string nameOfFile in FileNames)
{
listView1.Items.Add(nameOfFile);
}

}
}
}


Thats it..Now check your directory(here it is D directory)


Below is the Screen Shot:













Happy Coding..!
Regards,
Nitin Sharma

Wednesday, February 24, 2010

How to Convert Numerics/Digits into Words using C# .NET?



Hi All,
I came into thinking mode of having a system in where i enter "Numeric" values and get converted into "Words" within a single click using .NET framework.
For eg: 20,212 to " Twenty Thousand Two hundred Twelve" .
I googled and found the solution.
Below is the code (It is a C# Windows Application)


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Numeric;

namespace TestApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{


}
private void button1_Click(object sender, EventArgs e)
{
label1.Text = changeToWords(textBox1.Text, false);
}

public String changeNumericToWords(double numb)
{
String num = numb.ToString();
return changeToWords(num, false);
}
public String changeCurrencyToWords(String numb)
{
return changeToWords(numb, true);
}
public String changeNumericToWords(String numb)
{
return changeToWords(numb, false);
}
public String changeCurrencyToWords(double numb)
{
return changeToWords(numb.ToString(), true);
}
private String changeToWords(String numb, bool isCurrency)
{
String val = "", wholeNo = numb, points = "", andStr = "", pointStr = "";
String endStr = (isCurrency) ? ("Only") : ("");
try
{
int decimalPlace = numb.IndexOf(".");
if (decimalPlace > 0)
{
wholeNo = numb.Substring(0, decimalPlace);
points = numb.Substring(decimalPlace + 1);
if (Convert.ToInt32(points) > 0)
{
andStr = (isCurrency) ? ("and") : ("point");// just to separate whole numbers from points/cents
endStr = (isCurrency) ? ("Cents " + endStr) : ("");
pointStr = translateCents(points);
}
}
val = String.Format("{0} {1}{2} {3}", translateWholeNumber(wholeNo).Trim(), andStr, pointStr, endStr);
}
catch { ;}
return val;
}
private String translateWholeNumber(String number)
{
string word = "";
try
{
bool beginsZero = false;//tests for 0XX
bool isDone = false;//test if already translated
double dblAmt = (Convert.ToDouble(number));
//if ((dblAmt > 0) && number.StartsWith("0"))
if (dblAmt > 0)
{//test for zero or digit zero in a nuemric
beginsZero = number.StartsWith("0");
int numDigits = number.Length;
int pos = 0;//store digit grouping
String place = "";//digit grouping name:hundres,thousand,etc...
switch (numDigits)
{
case 1://ones' range
word = ones(number);
isDone = true;
break;
case 2://tens' range
word = tens(number);
isDone = true;
break;
case 3://hundreds' range
pos = (numDigits % 3) + 1;
place = " Hundred ";
break;
case 4://thousands' range
case 5:
case 6:
pos = (numDigits % 4) + 1;
place = " Thousand ";
break;
case 7://millions' range
case 8:
case 9:
pos = (numDigits % 7) + 1;
place = " Million ";
break;
case 10://Billions's range
pos = (numDigits % 10) + 1;
place = " Billion ";
break;
//add extra case options for anything above Billion...
default:
isDone = true;
break;
}
if (!isDone)
{//if transalation is not done, continue...(Recursion comes in now!!)
word = translateWholeNumber(number.Substring(0, pos)) + place + translateWholeNumber(number.Substring(pos));
//check for trailing zeros
if (beginsZero) word = " and " + word.Trim();
}
//ignore digit grouping names
if (word.Trim().Equals(place.Trim())) word = "";
}
}
catch { ;}
return word.Trim();
}
private String tens(String digit)
{
int digt = Convert.ToInt32(digit);
String name = null;
switch (digt)
{
case 10:
name = "Ten";
break;
case 11:
name = "Eleven";
break;
case 12:
name = "Twelve";
break;
case 13:
name = "Thirteen";
break;
case 14:
name = "Fourteen";
break;
case 15:
name = "Fifteen";
break;
case 16:
name = "Sixteen";
break;
case 17:
name = "Seventeen";
break;
case 18:
name = "Eighteen";
break;
case 19:
name = "Nineteen";
break;
case 20:
name = "Twenty";
break;
case 30:
name = "Thirty";
break;
case 40:
name = "Fourty";
break;
case 50:
name = "Fifty";
break;
case 60:
name = "Sixty";
break;
case 70:
name = "Seventy";
break;
case 80:
name = "Eighty";
break;
case 90:
name = "Ninety";
break;
default:
if (digt > 0)
{
name = tens(digit.Substring(0, 1) + "0") + " " + ones(digit.Substring(1));
}
break;
}
return name;
}
private String ones(String digit)
{
int digt = Convert.ToInt32(digit);
String name = "";
switch (digt)
{
case 1:
name = "One";
break;
case 2:
name = "Two";
break;
case 3:
name = "Three";
break;
case 4:
name = "Four";
break;
case 5:
name = "Five";
break;
case 6:
name = "Six";
break;
case 7:
name = "Seven";
break;
case 8:
name = "Eight";
break;
case 9:
name = "Nine";
break;
}
return name;
}
private String translateCents(String cents)
{
String cts = "", digit = "", engOne = "";
for (int i = 0; i < digit =" cents[i].ToString();" engone = "Zero" engone =" ones(digit);">


below is the screen Shot :






Thanks,
Nitin Sharma