XmlDocument xdoc = new XmlDocument();
xdoc.Load(Server.MapPath("~/pp1.xml"));
string PersonCount = xdoc.DocumentElement.SelectNodes("//persons/person").Count.ToString();
Response.Write(PersonCount);
A blog about web application development mainly on backend side
Sunday, November 25, 2012
Tuesday, October 16, 2012
ওয়ালটন প্রিমো (অ্যান্ড্রয়েড) রিভিউ
আমি নিজে অনেকদিন থেকেই সনি এরিকসন এক্সপেরিয়া এক্স এইট চালাই। এক বন্ধুর জন্য গত শনিবার গেলাম এন্ড্রয়েড ফোন কিনতে। প্রথমে ভেবেছিলাম যে সিম্ফোনি w5 নিবো কিন্তু পরে নেট ঘেটে দেখলাম যে দাম এবং কনফিগারেশনের দিক থেকে ওয়ালটন প্রিমো এগিয়ে। কিনলাম ওয়ালটন এর বিজয় সরনী এর শো রুম থেকে। কেনার পর একদিন ব্যবহার করার সুযোগ পেলাম। তাতে যা দেখলাম টাকার হিসেবে অসাধারন জিনিস (আমার মতে)।
Monday, September 24, 2012
Make your windows 7 laptop into wifi hotspot
Make sure you have installed Microsoft Virtual Wifi miniport adapter
Then make command as follows:
Then make command as follows:
C:\Windows\system32>netsh wlan set hostednetwork mode=allow ssid=MyWifi key=password keyUsage=persistent
To start your network
C:\Windows\system32>netsh wlan start hostednetwork
To Stop your network
C:\>netsh wlan show hostednetwork
Share your internet connection by going to network sharing center
Monday, June 11, 2012
Create a colorful flashlight in android
Create an android project in eclipse and pasted the following code in the main activity class:
package com.rayhan.nothing;
import java.util.Random;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;
public class AndruTestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View v=findViewById(R.id.mainlayout);
v.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Random rnd=new Random();
v.setBackgroundColor(rnd.nextInt());
}
});
}
}
//------------------------------------------------
And here is the xml file for the layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
android:background="@color/white"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>
package com.rayhan.nothing;
import java.util.Random;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;
public class AndruTestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View v=findViewById(R.id.mainlayout);
v.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Random rnd=new Random();
v.setBackgroundColor(rnd.nextInt());
}
});
}
}
//------------------------------------------------
And here is the xml file for the layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
android:background="@color/white"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>
Friday, March 30, 2012
Serialize and DeSerialize an object to a file in C#
Here is the code for serialization:
/// <summary>
/// Function to save object to external file
/// </summary>
/// <param name="_Object">object to save</param>
/// <param name="_FileName">File name to save object</param>
/// <returns>Return true if object save successfully, if not return false</returns>
public bool ObjectToFile(object _Object, string _FileName)
{
try
{
// create new memory stream
System.IO.MemoryStream _MemoryStream = new System.IO.MemoryStream();
// create new BinaryFormatter
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter _BinaryFormatter
= new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
// Serializes an object, or graph of connected objects, to the given stream.
_BinaryFormatter.Serialize(_MemoryStream, _Object);
// convert stream to byte array
byte[] _ByteArray = _MemoryStream.ToArray();
// Open file for writing
System.IO.FileStream _FileStream = new System.IO.FileStream(_FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write);
// Writes a block of bytes to this stream using data from a byte array.
_FileStream.Write(_ByteArray, 0, _ByteArray.Length);
// close file stream
_FileStream.Close();
// cleanup
_MemoryStream.Close();
_MemoryStream.Dispose();
_MemoryStream = null;
_ByteArray = null;
return true;
}
catch (Exception _Exception)
{
// Error
Console.WriteLine("Exception caught in process: {0}", _Exception.ToString());
}
// Error occured, return null
return false;
}
Here is the code for deserialize the object:
public object FileToObj(string _fileName)
{
FileStream fs = new FileStream(_fileName, FileMode.Open);
// create new BinaryFormatter
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter _BinaryFormatter
= new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
// Serializes an object, or graph of connected objects, to the given stream.
return _BinaryFormatter.Deserialize(fs);
}
/// <summary>
/// Function to save object to external file
/// </summary>
/// <param name="_Object">object to save</param>
/// <param name="_FileName">File name to save object</param>
/// <returns>Return true if object save successfully, if not return false</returns>
public bool ObjectToFile(object _Object, string _FileName)
{
try
{
// create new memory stream
System.IO.MemoryStream _MemoryStream = new System.IO.MemoryStream();
// create new BinaryFormatter
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter _BinaryFormatter
= new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
// Serializes an object, or graph of connected objects, to the given stream.
_BinaryFormatter.Serialize(_MemoryStream, _Object);
// convert stream to byte array
byte[] _ByteArray = _MemoryStream.ToArray();
// Open file for writing
System.IO.FileStream _FileStream = new System.IO.FileStream(_FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write);
// Writes a block of bytes to this stream using data from a byte array.
_FileStream.Write(_ByteArray, 0, _ByteArray.Length);
// close file stream
_FileStream.Close();
// cleanup
_MemoryStream.Close();
_MemoryStream.Dispose();
_MemoryStream = null;
_ByteArray = null;
return true;
}
catch (Exception _Exception)
{
// Error
Console.WriteLine("Exception caught in process: {0}", _Exception.ToString());
}
// Error occured, return null
return false;
}
Here is the code for deserialize the object:
public object FileToObj(string _fileName)
{
FileStream fs = new FileStream(_fileName, FileMode.Open);
// create new BinaryFormatter
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter _BinaryFormatter
= new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
// Serializes an object, or graph of connected objects, to the given stream.
return _BinaryFormatter.Deserialize(fs);
}
Wednesday, March 7, 2012
Checking availibility of WCF service
I've got one method from the book "Programming WCF Services" by Juval Lowy (page 71).
Code Snippet:
Code Snippet:
MetadataExchangeClient mexClient =
bool isServiceUp = true;
try
{
string address = "http://localhost/MyService.svc?wsdl";new MetadataExchangeClient(newUri(address), MetadataExchangeClientMode.HttpGet);
MetadataSet metadata = mexClient.GetMetadata();
// if service down I get the exception
}
catch (Exception ex)
{
isServiceUp = false;
}
I catch the Exception like {"Metadata contains a reference that cannot be resolved: "http://localhost/MyService.svc?wsdl"} System.Exception {System.InvalidOperationException}
Thursday, March 1, 2012
Get or Set Session in ashx handler
If you need to share session in ashx handler just use System.Web.SessionState.IRequiresSessionState this Interface
Like
public class login : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
......
}
Like
public class login : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
......
}
Subscribe to:
Posts (Atom)
What is DaemonSet in Kubernetes
A DaemonSet is a type of controller object that ensures that a specific pod runs on each node in the cluster. DaemonSets are useful for dep...
-
Both .NET and NodeJS are popular programming frameworks that have their own strengths and weaknesses, which makes for an interesting compar...
-
A DaemonSet is a type of controller object that ensures that a specific pod runs on each node in the cluster. DaemonSets are useful for dep...
-
Take the following Program.cs class as example - var builder = WebApplication . CreateBuilder ( args ); // Add services to the container...