Showing posts with label Tech Boosters. Show all posts
Showing posts with label Tech Boosters. Show all posts

Monday, June 2, 2014

.Net Zone: oops interview questions and answers for experienc...

.Net Zone: oops interview questions and answers for experienc...: What is abstraction in OOPS? Abstraction means to show only the necessary details to the client of the object. Let’s say you have a me...

Sunday, May 13, 2012

Procedure to bring your hard disk to Factory Setup

Recently I faced a situation where my OS was not booting. Also when I tried to install a fresh Windows 7 in it,  my hard disk was not getting formatted.
I followed the following Debug script to bring my hard disk to factory setup & after that I could install the Windows 7, in the way I wanted.

NB : 1. We should not go for more than 3 partition, else system might slow up.
        2. Make all partition as primary (by Win 7 DVD). Avoid creating Dynamic drives, else going further they cant be modified.

Procedure for reverting to  Factory Setup :

Insert any boot able Floppy / CD / DVD & navigate to RAM Disk (By default the prompt goes there).
Then type below commands in command prompt (With CAPS lock ON) :

DEBUG
-F 200 L1000 0
-A CS:100
xxxx:0100 MOV AX,301  (NB: XXXX could be anything, just ignore & type rest command)
xxxx:0103 MOV BX,200
xxxx:0106 MOV CX,1
xxxx:0109 MOV DX,80


 NOTE:  Type 80 for the Main hard drive - HD 0, or type 81 for the Second hard drive - HD 1.


xxxx:010C INT 13
xxxx:010E INT 20
xxxx:0110 (Leave this line blank and press the key)
-G
The message, Program terminated normally, appears. Turn off the computer by pressing the power button. On the next startup the hard drive must be partitioned and formatted.



If anyone tried this procedure & found helpful, requesting him / her to leave a message here as comment / feedback.


Thanks,
Bikash Patra

Wednesday, April 18, 2012

Jquery window & pop up

I was trying to hide the widow, while trying to download an exe through FTP protocol...
I was using :
window.open("ftp://10.32.138.74/DiagnosticLauncher.exe", 1, 'width=50,height=30,false');

When I used Jquery equivalent of it, I could fix that problem easily :)


$jq(window).attr("location","ftp://10.32.138.74/DiagnosticLauncher.exe");
This version works well with jQuery 1.6.2.
Or using JS we could achieve the same : 
window.location = "http://www.page-2.com";

For Jquery pop up

popup window

$(selector).popupWindow({options});

jQuery plugin (jquery.popupWindow.js) used to create popup windows.
Demo Code :
> href="http://www.yahoo.com" title="yahoo.com" class="example1demo">open popup 
 type="text/javascript"> 
$('.example1demo').popupWindow({ 
height:500, 
width:800, 
top:50, 
left:50 
}); 

Ref link : http://swip.codylindley.com/popupWindowDemo.html


Wednesday, April 4, 2012

Serialize and Deserialize an Object to an XML File in C# 2.0

The example in this tip uses an ArrayList object to serialize, deserialize, and store itself in an XML file. However, you can also use user-defined objects. First, add items to an ArrayList object:

ArrayList myItems = new ArrayList();
myItems.Add("item1");
myItems.Add("item2");
myItems.Add("item3");

Next, you need to serialize the myItems object and store it in a file named myItems.xml:

System.Xml.Serialization.XmlSerializer serializer =
new System.Xml.Serialization.XmlSerializer(typeof(ArrayList));
System.IO.TextWriter writer =
new System.IO.StreamWriter("myItems.xml", false);
serializer.Serialize(writer, myItems);
writer.Close();

Finally, deserialize the same object from myItems.xml:

System.Xml.Serialization.XmlSerializer serializer =
new System.Xml.Serialization.XmlSerializer(typeof(ArrayList));
System.IO.TextReader reader =
new System.IO.StreamReader("myItems.xml");
ArrayList ObjItems = (ArrayList)serializer.Deserialize(reader);
reader.Close();

Thursday, July 21, 2011

Converting Dataset to a C# model class

Problem statement: 

My Webservice is returning a dataset comprising of 1 table, which contains 135 columns. I need to build a model class (in C#), which should have all 110 column names as property name of the class.
Is there any way by which I can use the file stream writer & build my class?
Possible Solution:
Step 1: Convert your Dataset to a XML doc:
            var xmlSW = new System.IO.StreamWriter(@"c:\xml\Krishna.xml");
            myDataset.WriteXml(xmlSW, System.Data.XmlWriteMode.WriteSchema);
            xmlSW.Close();
Step 2: Convert your XML document to XSD doc.
   -> Open Visual Studio Command Promt.
   -> Type : xsd c:\xml\Krishna.xml (that is the path of the xml file.)
For Eg: C:\Windows\system32>xsd c:\xml\krishna.xml
Microsoft (R) Xml Schemas/DataTypes support utility [Microsoft (R) .NET Framework, Version 4.0.30319.1] Copyright (C) Microsoft Corporation. All rights reserved.
Writing file 'C:\Windows\system32\krishna.xsd'.
Step 3: Convert your xsd to C# class.
   -> Open Visual Studio Command Promt.
   -> Type : xsd krishna.xsd /classes
For Eg: C:\Windows\system32>xsd krishna.xsd /classes
Microsoft (R) Xml Schemas/DataTypes support utility [Microsoft (R) .NET Framework, Version 4.0.30319.1] Copyright (C) Microsoft Corporation. All rights reserved.
Writing file 'C:\Windows\system32\krishna.cs'.
NB: The generated property name can be renamed properly (if not proper) by Resharper or similar tools.
The output class file might contain some unnecessary information that u need to clean up. So this method is suitable if your dataset is returning huge tables containing hundreds of columns & you dont want to copy paste all of them manually to create your own mapping class.
Once you get the structure (class), you can use XmlSerializer to convert it to object or viceversa.

Thursday, February 24, 2011

Easy steps to solve the rutime error: "cant save the session id because it is invalid"

.Net developers often get this irritating run-time error.
" Cant save the session id because it is invalid. Session ID= yddfdldsfdiewre .... ".




 If you face such error, then
>>Press F12 ( i.e. open IE Developer Tool Bar).
>>Click on Cache Tab.
>>Clear Browser cache for this domain.
>>Clear Session Cookies.
>>Clear cookies for this domain.

>>Then kill the ASP.Net Dev Server.
>>Restart the application. It should function properly.
All The best :-)

Thursday, February 17, 2011

Event Binding & attribute setting example in Jquery

    $("#txtZipCode").unbind();   //Unbind all existing events on text box called txtZipCode

    $('#txtZipCode').bind('keypress', function () { $('#txtZipCode').alphanumeric(); });   //Binds alphanumeric      plugin to the KeyPress event of the text box.

    $('#txtZipCode').attr("maxLength", "5");   //Sets the maxLength attribute to 5

Tuesday, January 4, 2011

[C#] Correct way of throwing exception from a catch block


There are two ways to catch and re-throw an exception, below the two code snippets:
Snippet #1:
   1:  try
   2:  {
   3:   
   4:  }
   5:  catch(Exception ex)
   6:  {
   7:    throw ex;
   8:  }
Snippet #2:
   1:  try
   2:  {
   3:   
   4:  }
   5:  catch(Exception ex)
   6:  {
   7:    throw;
   8:  }
When you use snippet #1, you will re-throw the same exception object and as result of this the original stack trace will be lost. Snippet #2 will maintain the original stack trace, this is very useful for debugging.
One of the try/catch general exception handling guidelines says:
“Do not rethrow by throwing the same exception object. This causes the stack trace for the original exception to be lost--use a lone "throw;" statement (without an object following it) to "rethrow" a catch exception.”
The best way to see the difference is with a code example:
   1:  class Program
   2:  {
   3:    static void Main(string[] args)
   4:    {
   5:      try
   6:      {
   7:        Method1();
   8:      }
   9:      catch (Exception ex)
  10:      {
  11:        throw;
  12:      }
  13:    }
  14:   
  15:    public static void Method1()
  16:    {
  17:      Method2();
  18:    }
  19:   
  20:    public static void Method2()
  21:    {
  22:      throw new Exception();
  23:    }   
  24:  }
The following stack trace will be produced by the code example above:
   at ConsoleApplication2.Program.Method2()
   at ConsoleApplication2.Program.Method1()
   at ConsoleApplication2.Program.Main(String[] args)
   at System.AppDomain.ExecuteAssembly(Assembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
When you use throw ex; instead of throw; you will get:
   at ConsoleApplication2.Program.Main(String[] args)
   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
As you see the stack trace don’t have the calls to Method1 and Method2, so when you use throw ex; you will lose essential debug information.