asp.net

Pointer in C# (.NET) and why .NET not allow to use as safe

I tried to use pointer in C# because I use to do the same in C++. But I cann’t do this in .NET (C#) cause the pointer is unsafe with every reason.
1. Pointer can point to every address.
2. If you cann’t control the pointer well as “Memory Leak” then you will get the memory problem.
3. You will get the error If you destry one object and there were some pointer still point to that object. That pointer will point to null.

The problem above show the unsafe of pointer then .Net not allow to use it. Because of most reason to use pointer will use for the low level programming. So C++ or VB6 will be better to use it. :D

I have searched the google and found one reference site that explain why you cann’t use pointer in .NET. This article is awsome. Let’s see this reference : unsafe .NET pointer

Get root path, root url and any url of your website asp.net

This technique will help you to get url and path of server that you want.
Let’s see this result.

When I place this script on this path below :

http://www.aspgod.com/test/mappath/Default.aspx

And the script is :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Request.Url.AbsoluteUri  //  http://www.aspgod.com/test/mappath/Default.aspx
Request.Url.AbsolutePath  //  /test/mappath/Default.aspx
Request.ApplicationPath  //  because I'm not set the virsual directory indeep of the server
 
Server.MapPath("") // d:\xxx\zzz\aspgod.com\httpdocs\test\mapath
Server.MapPath("Default.aspx") // d:\xxx\zzz\aspgod.com\httpdocs\test\mapath\Default.aspx
 
if you want to get the root path and root url.
You must enter this script below:
 
Request.Url.AbsoluteUri.Replace(Request.Url.AbsolutePath,string.Empty) + Request.ApplicationPath
//  www.aspgod.com/
Server.MapPath(this.Request.ApplicationPath).Replace("/", "\\")
-> d:\xxx\zzz\aspgod.com\httpdocs

—–

If I use this script on localhost the the result is :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Request.Url.AbsoluteUri  //  http://localhost:1904/aspgod/test/mappath/Default.aspx
Request.Url.AbsolutePath  //  /test/mappath/Default.aspx
Request.ApplicationPath  //  /aspgod
 
my project is in this path E:\--- Other Project ---\aspgod\program\aspgod
Server.MapPath("") // E:\--- Other Project ---\aspgod\program\aspgod\test\mapath
Server.MapPath("Default.aspx")
// E:\--- Other Project ---\aspgod\program\aspgod\test\mapath\Default.aspx
 
if you want to get the root path and root url.
You must enter this script below:
 
Request.Url.AbsoluteUri.Replace(Request.Url.AbsolutePath,string.Empty) + Request.ApplicationPath
//  http://localhost:1904/aspgod
Server.MapPath(this.Request.ApplicationPath).Replace("/", "\\")
// E:\--- Other Project ---\aspgod\program\aspgod

GridView RowDataBound Get DataSource By Row

When using RowDataBound (the GridView’s method) and want to get the data by row. Because RowDataBound work on row by row when initial GridView. How to get data from datasource in method RowDataBound ? Use Eval() method will help you

protected void gvView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
_SumTotal += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, “Total”));
}
}

// “Total” is a data field in database
// _SumTotal is a global valuable on this page

In this example you can get all total summary in gridview datasource.