Sunday, March 23, 2014

Create byte array from string and vice versa

Here is the code

static byte[] GetBytes(string str)
{
    byte[] bytes = new byte[str.Length * sizeof(char)];
    System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
    return bytes;
}

static string GetString(byte[] bytes)
{
    char[] chars = new char[bytes.Length / sizeof(char)];
    System.Buffer.BlockCopy(bytes, 0, chars, 0, bytes.Length);
    return new string(chars);
}

Monday, May 20, 2013

Remove index.php from Codeigniter application

I have got a nice post here http://www.danielwmoore.com/extras/index.php?topic=7691.0

Sunday, May 19, 2013

Send 160 character sms instead of 80 character on Samsung galaxy s3

If you can not send sms of 160 character using your samsung galaxy s3 then you can use handcent app from playstore.

Using Handcent should fix the problem.

https://market.android.com/details?id=com.handcent.nextsms&hl=en

Tuesday, February 26, 2013

Generate Class from table using T4 template

here is a t4 file. save it using .tt extension and change the connection accordingly and drag to visual studio solution.



Thursday, January 17, 2013

Retrieving all values from POST in asp.net

Here is the code:
<%@ Page Language="C#" CodeFile="~/listen.aspx.cs" Inherits="listenerTest.listen" %>
<%
Response.ClearContent();
Response.ClearHeaders();
Response.Clear();
Response.AddHeader("Content-Type", "text/plain");

if (Request.Form.Count != 0)
{
string all = "";
foreach (string name in Request.Form.AllKeys)
{
string value = Request.Form[name];
// Do something with (name, value).
all += "key:" + name + "value:" + value;
}
}

Response.End();
%>

Thursday, January 3, 2013

Simple Form post from Codebehind C#

Here is the sample code:
private void PostToUrl(string url, string parameters)
{
string URI = url;
string myParameters = parameters;//"param1=value1&param2=value2&param3=value3";

using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string HtmlResult = wc.UploadString(URI, myParameters);
}
}