Pages

Wednesday, December 9, 2009

Escape Sequences


While Coding we use many special characters, and we have seen some characters which start with a backslash ("\"). All the characters which starts from backslash ("\") is known as the escape sequence. There are several escape sequence are used in the c# here are the list of that. you can use them according to the use..

\a Bell (alert)
\b Backspace
\f Formfeed
\n New line
\r Carriage return
\t Horizontal tab
\v Vertical tab
\' Single quotation mark
\" Double quotation mark
\\ Backslash
\? Literal question mark
\ooo ASCII character in octal notation
\xhh ASCII character in hexadecimal notation
\xhhhh Unicode character in hexadecimal notation if this escape sequence is used in a wide-character constant or a Unicode string literal.


Hope the information was useful.. Happy coding!!!!


Thanks
Anil Kumar Pandey
System Architect, MVP
Mumbai, Maharshtra

Tuesday, December 8, 2009

Executing a batch file with parameter from C#

hello All,
Some time we need to run or execute a batch file inside our code behind using the c# code, for that reason here I am going to show that how can we run a batch file inside the code behind. We can also pass the required parameter to run the file. Please check the following code.


try
{
System.Diagnostics.Process() objProcess = new System.Diagnostics.Process(); // Create the process object
objProcess.
StartInfo.FileName = "c:\\Anil\\testAnil; //batch File Name
objProcess.StartInfo.Arguments = "
c:\\Anil\\testAnil" + strXmlFileName;//paramter file name
objProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
objProcess.Start();
//Wait until the process passes back an exit code
objProcess.WaitForExit();
//Free resources associated with this process
objProcess.Close();
}
catch (Exception ex)
{
MessageBox.Show("
Could not start process " + FileNameNew, "Error");
}


I hope this will solve your problem. Waiting for your comments..!! Happy Coding!!


Thanks
Anil Kumar Pandey
System Architect, MVP
Mumbai, Maharshtra

Thursday, December 3, 2009

Reading a PDF file content using iTextSharp

hi there,
iTextSharp has made reading the DLL so easy, that using a simple function we can read the content of the PDF file. We just need to use this dll, this can be easily downloaded from the following sites.


Using the following fuction we can read the PDF file by specifying the page no.. here is the code.



using iTextSharp.text.pdf;


string filename = "FileName";
PdfReader reader
= new PdfReader(filename);
int intPageCount = reader.NumberOfPages;
string strContent = ParsePdfText(filename, 1, intPageCount);



public string ParsePdfText(string sourcePDF, int fromPageNum,int toPageNum)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
try
{
PdfReader reader
= new PdfReader(sourcePDF);
byte[] pageBytes = null;
PRTokeniser token
= null;
int tknType = -1;
string tknValue = string.Empty;
for (int i = fromPageNum; i <= toPageNum; i += 1)
{
pageBytes
= reader.GetPageContent(i);
if ((pageBytes != null))
{
token
= new PRTokeniser(pageBytes);
while (token.NextToken())
{
tknType
= token.TokenType;
tknValue
= token.StringValue;
if (tknType == PRTokeniser.TK_STRING)
{
sb
.Append(token.StringValue);
}

else if (tknType == 1 && tknValue == "-600")
{
sb
.Append(" ");
}
else if (tknType == 10 && tknValue == "TJ")
{
sb
.Append(" ");
}
}
}
}
}
catch (Exception ex)
{
MessageBox
.Show("Exception occured. " + ex.Message);
return string.Empty;
}
return sb.ToString();
}

The varibale strContent will contain all the data present in the PDF file. using the starting page no and End page no we can spicy the limit from which page to which we want to read the content.

Isn't that so easy.. waiting for all your comment..

Thanks
Anil Kumar Pandey
System Architect, MVP
Mumbai, Maharshtra

Wednesday, October 28, 2009

Have you seen date beyond 31 in a Professional site?????????

hi,

while searching a flight for my home town i found an interesting thing in a site, there were option to select the date which can never come like 32 october 2009,33 october 2009,34 october 2009 up to 36 October 2009.

how can a professional developer do a mistake like this..?????????????

please have a look... 32 October 2009

in the above link please check the Drop down for the Flight Status:option...



waiting for your comments







Thanks
Anil Kumar Pandey
System Architect, MVP
Mumbai, Maharshtra



Intresting new features of Windows 7

hi all,
have a look to the interesting new features of the windows 7, the latest operating system from windows. please follow the below line...



Thanks
Anil Kumar Pandey
System Architect, MVP
Mumbai, Maharshtra

Thursday, October 8, 2009

Downloading a file

Hello all,

here is the code for downloading any file from the specified location using the file stream.. Please refer the code for the same..

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim root As String = "C:\Inetpub\wwwroot\Test\"
Dim filepath As String = "C:\Inetpub\wwwroot\Test\Test.2.zip"
If File.Exists(filepath) And filepath.StartsWith(root) Then
Dim filename As String = Path.GetFileName(filepath)
Response.
Clear()
Response.
ContentType = "application/octet-stream"
Response.
AddHeader("Content-Disposition", "attachment; filename=""" & filename & """")
Response.
Flush()
Response.
WriteFile(filepath)

End If
End Sub

Thanks
Anil Kumar Pandey
System Architect, MVP
Mumbai, Maharshtra

Friday, October 2, 2009

On Top of the World Today!!!!!!

Hello everyone,
I am very happy to inform you all that i have got the Prestigious Microsoft MVP(Most Valuable Professional) award today.. I dont have words to explain my feeling right now, this is all my friends good wishes that i have got this award. i would thanks to all my friends who have supported me in each moment of my life...

you can see the announce lise here.. MVP


Thanks
Anil Kumar Pandey
System Architect
Mumbai, Maharshtra

Friday, September 18, 2009

Reading a word file Using c#

Reading a word file in c# is very simple we just need to add the reference of the COM component in our application. Click on Add >> Reference and Select the COM tab, under that tab please select the Microsoft object library 9.0 or higher. and after this use the following code to read any file...


Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
object file = "D:\\Anil\\test\\testfile.doc"; // path for word file
object nullobj = System.Reflection.Missing.Value;
Microsoft.
Office.Interop.Word.Document doc = wordApp.Documents.Open(ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,ref nullobj, ref nullobj, ref nullobj, ref nullobj);
doc.
ActiveWindow.Selection.WholeStory();
doc.
ActiveWindow.Selection.Copy();
IDataObject data
= Clipboard.GetDataObject();
string allText = data.GetData(DataFormats.Text).ToString();
doc.
Close(ref nullobj, ref nullobj, ref nullobj);
wordApp.
Quit(ref nullobj, ref nullobj, ref nullobj);
Textbox1.
Text = allText);


Happy Coading!!!

Thanks
Anil Kumar Pandey
System Architect
Mumbai, Maharshtra

Kontera