vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Wednesday, September 26, 2012

Add or Register HTTP Handlers in web.config file in asp.net


Recently I had faced the problem to add HTTP handler file in web.config file. I have a requirement to restrict my document file, so I have create http handler for the document, But when I try to register the file I got the below error.

Parser Error Message: Could not load file or assembly 'DocHandler' or one of its dependencies. The system cannot find the file specified.
Then I goggled to find the solution for the problem, after doing deep search I got one solution that use class instead of handler file.

Then I follow the below steps to solve my issues.
1. i create separate class file in the name of Dochandler.cs
2. Create namespace for the class file Dochandler
3. Then I interface IHttpHandler, and I use same code wheich I used in the handler.
4. I saved the filein App_code directory.
Next in web.config file you have to code like below in httpHandlers tag
<add verb="*" path="*.doc" type="DocHandler.DocHandler,App_Code"/>

Here Verb indicates Get Request and Post Request (* allows the both)
Path indiactes the follow the extension type.
Type indiactes filename and the directory
That’s it Now you can run the project it will works likecharm………
Post your comments if its useful to you……..

Saturday, September 15, 2012

Create virtual device Galaxy Tablet for android simulator in eclipse.


For creating simulator for android galaxy tablet you can follow the below steps.

Step 1: Open Android virtual device manager in Eclipse
Step 2: Create an new Virtual device
Step 3: For target and resolution give the settings for both
Target: Android 3.1 (API 12) (if you don’t have this API level then download the API)
Resolution:  1280*800
That’s it now you can start the virtual device
This is the way you can create simulator for Tablet, now you can test your android application in Tablet
Simulator.

Friday, September 14, 2012

android.os.NetworkOnMainThreadException


Hi..
When I work with android web service project,From starting I used my application in android mobile its working perfectly with webservice,But when I move tablet its shows an below error.
Reason tablet have API 12, Thread policy has changed from the API Level 11
When you are using web service if it take more time then you can get the this type of error..
To overcome this error you have to add the below code on the starting of web service code.

if (android.os.Build.VERSION.SDK_INT > 9) {
                     StrictMode.ThreadPolicy policy =
                           new StrictMode.ThreadPolicy.Builder().permitAll().build();
                     StrictMode.setThreadPolicy(policy);
              }

After I used the above my problem would be solved. I hope it will help someone…
Post your valuable comments here………

Serialization and Deserialization in C# and Serialization usages with an example


Serialization:
Serialization is the process of convert of .Net object into another format like xml or Binary format.
This process used when we need save the object data as a file or transfer across through the network, so this type conversion is called as serialization.

The different types of serialization are

· Binary Serialization

· XML Serialization

· SOAP Serialization

Binary Serialization

Binary serialization is the process where you convert your .NET objects into byte stream. In binary serialization all the public, private, even those which are read only, members are serialized and converted into bytes. So when you want a complete conversion of your objects to bytes then you can make use of binary serialization.

When to use Binary Serialization

Object contains secure data then you can go with binary serialization, because it’s not easily human readable its completely convert the whole format.

Its file size is very small

If the two deserialize system has same also you can use Binary Serialization.

XML Serialization
It’s the process .Net object state is transformed into xml format in xml serialization.so the whole object has stored as xml file.

In XML serialization only the public properties and fields of the objects are converted into XML. The private members are not taken into consideration in XML serialization.

When to use XML Serialization

If you have an application in different platform then you can use XML Serialization.

If you are going to use only public members then you can use XML Serialization.

SOAP Serialization
It likes XML serialization. When you serialize object to SOAP format it conforms to the SOAP specification.

Example for XML Serialization:

Serialize the Object:
Initially I create one class for doing serialize
[XmlRoot("serialName")]
        public class ser
    {
        [XmlElement("Name1")]
        public String str1;
        [XmlElement("Name2")]
        public String str2;
        [XmlElement("Name3")]
        public String str3;
    }

XML Serialization Code:
Here I create new object for class and convert into xml format and save the file as new.xml
  ser s = new ser();
        s.str1 = "name11";
        s.str2 = "name22";
        s.str3 = "name33";
        FileStream str = new FileStream(Server.MapPath("new.xml"), FileMode.Create);
        XmlSerializer xmls = new XmlSerializer(s.GetType());
        xmls.Serialize(str, s);
        str.Dispose();

XML Deserialization Code:
Here I Deserialze the convert xml object in to class
  ser s = new ser();
        StreamReader strread;
        strread = new StreamReader(Server.MapPath("new.xml"));
        XmlSerializer xmls = new XmlSerializer(s.GetType());
        s = (ser)xmls.Deserialize(strread);
        strread.Close();

Example for Binary Serialization:
Serialize the Object:
Initially I create one class for doing serialize
[Serializable]
    public class ser
    {
        public String str1;
        public String str2;
        public String str3;
    }

Binary Serialization Code:
Here I create new object for class and convert into xml format and save the file as new.xml
Instead of class you can convert string type also..
  ser s = new ser();
        s.str1 = "name1";
        s.str2 = "name2";
        s.str3 = "name3";
        string stre = "vijay";
        FileStream Fs = new FileStream(Server.MapPath("Bin.data"), FileMode.Create);
        BinaryFormatter BF = new BinaryFormatter();
        BF.Serialize(Fs, s);
        Fs.Close();

Binary Deserialization Code:
Here I Deserialze the convert xml object  in to class
ser s = new ser();
        FileStream Fs = new FileStream(Server.MapPath("Bin.data"), FileMode.Open);
        BinaryFormatter BF = new BinaryFormatter();
        s = (ser)BF.Deserialize(Fs);
        Fs.Close();



Tuesday, September 11, 2012

Create custom Dashboard icon with text in android application


Here I would like to share the bit of useful information about android application. When creating android application everyone have need to create or show button in an application. Here I share simple and elegant method to create android button using linear layout.
Ina previous article I wrote to use image in a button, for your reference I mention the link as below


Requirement needed to create
1.       First choose your icon button as in same width and height.
Normally android they are two normally used to create button icon i.e. Linear layout or grid view layout
Here I chose linear layout with horizontal orientation
First needs to create style code in styles.xml files in values folder.
File style.xml
Code:
<style name="DashboardButton">
        <item name="android:layout_gravity">center_vertical</item>
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:gravity">center_horizontal</item>
        <item name="android:drawablePadding">2dp</item>
        <item name="android:textSize">16dp</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">#034486</item>
        <item name="android:background">@drawable/button</item>
         <item name="android:layout_weight">1</item>
         </style>




In your main layout copy the below code and change the image you want to set for the button..
<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"      
        android:orientation="vertical" >
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingTop="40dp" >

            <Button
                android:id="@+id/btn1"
                style="@style/DashboardButton"
                android:drawableTop="@drawable/img1"
                android:text="Add"
                android:textSize="14dp" />

            <Button
                android:id="@+id/btn2"
                style="@style/DashboardButton"
                android:drawableTop="@drawable/img2”
                android:text="Delete" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingTop="20dp" >

            <Button
                android:id="@+id/btn3"
                style="@style/DashboardButton"
                android:drawableTop="@drawable/img3"              
                android:text="edit"
                android:textSize="14dp" />

            <Button
                android:id="@+id/btn4"
                style="@style/DashboardButton"
                android:drawableTop="@drawable/img4"              
                android:text="Display"
                android:textSize="14dp" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingTop="20dp" >

            <Button
                android:id="@+id/btn5"
                style="@style/DashboardButton"
                android:drawableTop="@drawable/img5"
               
                android:text="Store"
                android:textSize="14dp" />
              
        <Button
                android:id="@+id/btn6"
                style="@style/DashboardButton"
                android:drawableTop="@drawable/img6"
                android:text="History"
                android:textSize="14dp" />
     

        </LinearLayout>
    </LinearLayout>


Here store all the images in drawable folder and we set the style for every button as dashboard button
That’s it now you can run view the images are aligned in  your layout
Post your comments here