July 2007 - Posts
Below is a code which will call a function using reflection. Note that if the function exists in an outside dll, you have to use the , separator in the className. for sure the second parameter is the name of
the function you want to invoke and the third parameter is the parameters sent to that function if exists, this parameter is of type object[].
Like i already mentioned if the function is in an external dll, send the first parameter (Class1,v.dll).
public static void CallFunctionByReflection(string className,string functionName,object[] arguments)
{
Type theType = null;
Object theObj = null;
MethodInfo DownloadInfo = null;
string [] type = className.Split(',');
try
{
if(type.Length == 1)
{
theType = Type.GetType(type[0]);
}
else
{
theType = Assembly.Load(type[1]).GetType(type[0]);
}
theObj = Activator.CreateInstance(theType);
try
{
DownloadInfo = theType.GetMethod(functionName);
if (arguments != null)
{
DownloadInfo.Invoke(theObj, arguments);
}
else
{
DownloadInfo.Invoke(theObj, null);
}
}
catch (System.Reflection.AmbiguousMatchException ame)
{
Type[] typeParams = new Type[arguments.Length];
for (int ind = 0; ind < typeParams.Length; ind++)
typeParams[ind] = typeof(System.String);
DownloadInfo = theType.GetMethod(functionName, typeParams);
DownloadInfo.Invoke(theObj, arguments);
}
}
finally
{
theType = null;
theObj = null;
DownloadInfo = null;
}
}
Don't forget to import the System.Reflection namespace.
Hope this helps,
I just passed "Developing XML Web Services and Server Components with Microsoft Visual C# .Net and the Microsoft .Net Framework" exam. Now i'm officially a Microsoft Certified Application Developer.
Whoever needs any information about getting this certification i'm ready to help.
Best Regards,
There are a lot of ways to display a "Please Wait" message on the webform while executing some logic in your code behind. Below is the implementation
First thing you need to do is to create a div HTML server control inside the form tag.
<div id="divWaitMessage" runat="server" style='WIDTH:100%;HEIGHT:30%'>
<p><b>Please Wait ...</b></p>
</div>
Second you need to add a meta tag to refresh the page after a specific time to get the result with a specified parameter in the query string.
<meta http-equiv="refresh" content="4;url=?id=1"/>
The above code will refresh the page after 4 seconds passing id=1 as a query string parameter.
Third and final thing, you should add the below code at page_load event which will, by default, set the visibility of the div control to true to show the message and after the page refreshes with the specified quey string, it will display a message "Data is retrieved" ( just for testing, in your case you can do whatever functionality you need on the server)
private void Page_Load(object sender, System.EventArgs e)
{
// Hide the div control
divWaitMessage.Visible = false;
if(Request.QueryString["id"] == null)
// Show the "Please Wait" message
divWaitMessage.Visible = true;
else
// Do some processing
Response.Write("Data is retrieved");
}
Hope this Helps,
HC
In this post, you will get an idea about the process of converting a VS 2003 project to VS 2005 web application. The web application project uses the same approach of a web project including the compilation into a single assembly.
Web Application projects in VS 2005 requires you to install an add in and an update
1- VS 2005 Service pack 1
2- This is an update to support Web Application Projects available as a Visual Studio 2005 add-in
Then all you need to do is to open your VS 2003 project using the VS 2005 so that the conversion wizard will run.
For more information, Check the below link
http://msdn2.microsoft.com/en-us/library/aa730880(vs.80,d=printer).aspx
Hope this helps,
HC
I encountered a problem where i needed to delete a folder from my application root folder at Session_End event. The folder name was assigned by the session id. I tried to access the session using HttpContext.Current object but in this time, the object is null because there is no web request however i looked at the HttpApplication class in which the Global class is derived, i found out a property called Session. Using the Session property, you can access all the session properties, methods.
protected void Session_End(Object sender, EventArgs e)
{
string sessionID = Session.SessionID;
Session.Abandon();
}
Best Regards,
HC