Sunday, August 11, 2013

Working with multiple AppDomain

AppDomain is a very use-full, when we are working with same assembly of multiple version. here is a sample code which will execute different assembly (but with same name and same method). what you need to do before? Assuming you have below folder structure to compile project

1. Create an interface (not important, but it is good to have)


build this project to "Binaries" folder
2. Create another project, which is we are going to execute (say V1)

 

 build this project to "V1" folder

3. Create another project, which should be same as above "V1" project.( do not change namespace name, class name and method name)
just change the return string as "This is calling from "V2" (ie string msg = "This is calling from V2";)

build this project to "V2" folder

4. Now we need to create Main project to run this all. Create a console application.

a. add a method, which shuld create new appDomain.


(Click on the above image to view in actual size)

now we are going to run this all.

Here we are not refer any of those 2 assemblies, but we will load assembly by using "reflection".


(Click on the above image to view in actual size)

Monday, September 7, 2009

SQL Server Case sencitive Query

Just put COLLATE Latin1_General_CS_AS allong with WHERE condition

ex:

SELECT * from tbl_User
WHERE State COLLATE Latin1_General_CS_AS = 'nc'

Wednesday, August 26, 2009

calling webservice from javascript with parameters

below is a simple javascript to tell you how to call web service with parameter
It will give you state and City for a zipcode you given
please assume there is 3 text boxes txtZip, txtState and txtCity
<script type="text/javascript">
var WebReq = null;
function findZip() {

//create dom
if (window.XMLHttpRequest)
WebReq = new XMLHttpRequest();
else if (window.ActiveXObject) {
if (new ActiveXObject("Microsoft.XMLHTTP"))
WebReq = new ActiveXObject("Microsoft.XMLHTTP");
else
WebReq = new ActiveXObject("Msxml2.XMLHTTP");
}

//url of webservice. see last, which is the name of our method to call
var url = "http://localhost:2508/MyProject/MyWebService/Service1.asmx/getCityState";
WebReq.open("post", url, true);
WebReq.setRequestHeader("Host",http://myproject/);
WebReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
WebReq.setRequestHeader("Content-Length","100");

//now mention method name (here is Result, check below i declared the method Result() ), ie after sending request , it will call this method to execute web response
WebReq.onreadystatechange = Result;
//taking zipcode from txtZipCode
var vZipCode = document.getElementById('');
//Adding Parameter ZipCode
WebReq.send("ZipCode=" + vZipCode.value);
}
function Result()
{
if (WebReq.readyState == 4 && WebReq.status == 200)
{
var dsRoot=WebReq.responseXML;
var City = dsRoot.getElementsByTagName('City')[0].firstChild.nodeValue;
var State = dsRoot.getElementsByTagName('State')[0].firstChild.nodeValue;
//Setting New value to city and State
var vCity = document.getElementById('');
var vState = document.getElementById('');
vCity.value = City;
vState.value= State;
}
}

Thursday, August 20, 2009

InnerText problem in firefox

its tue that innerText property does not support firefox, but it will work in IE. This is one of the issues facing on web developers. Here is my solution

below example will store 100 in label lblPremAmt.

firefox support textContent property which is equivalent to innerText in IE.

var vlblPremAmt = document.getElementById("<%= lblPremAmt.ClientID %>");

if(document.all)
{
vlblPremAmt.innerText = 100;
}
else
{
vlblPremAmt.textContent = 100;
}

Monday, August 3, 2009

call and execute a method using HttpWebRequest

Here is test code will call and execute a method in some server and retrive xml output.


string Qstring = "name=Alex&age=20";
string url = "https://mywebserver.com/websites.exe";
string data = Qstring; HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);

request.Method = WebRequestMethods.Http.Post;
request.ContentLength = data.Length;
request.ContentType = "application/x-www-form-urlencoded";

StreamWriter writer = new StreamWriter(request.GetRequestStream());
writer.Write(data);
writer.Close();

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());

strMVRXML = reader.ReadToEnd(); response.Close();
System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
xDoc.LoadXml(strXML);

Tuesday, May 12, 2009

how to get error message from error no in SQL server

SELECT * FROM master.dbo.sysmessages
WHERE error = 8115 AND msglangid = 1033

Tuesday, March 24, 2009

Asp.net Querystring Encrypt

ur query string in url address will be encrypted but u can access querystring using
Request.QueryString["<QueryStringName>"].
no need to add any xtra code, just follow below 2 steps

1. Download .cs file from http://blog.madskristensen.dk/post/HttpModule-for-query-string-encryption.aspx

2. modify web config file


<httpModules>
<add type="QueryStringModule" name="QueryStringModule" />
</httpModules>