Thursday, February 7, 2008

confusing file path for web developer .net

Are you one of the developer always confuse whith this kind of path e "games/alien.jpg" or "../games/alien.jpg" or "/games/alien.jpg" ? Even if you know the meaning, i am sure you still have problem of this because the path is constructed as it depends how the caller is located. Seem to be over complicated here. :)

I am one of the developer that alwasys confuse with file path that looks like <*img src=".../love/app/basic.jpg" /*>". i really do not like because it can be problematic especially if you are ASP.NET developer that uses master pages across the pages.

if you are one of those guy that always experince broken links, I have an elegant solution to this problem.

Given a virtual directory named site, which can be accessibled as http://localhost/site and you have a file which located at http://localhost/site/games/alien.jpg

to effectively locate the alien.jpg, you got to use this

ResolveUrl("~/games/alien.jpg")

In this way, you won't be confused how the file is located. ~ represents the parent virtual path.

Ok, if you wish to upload the file to the server using the ResolveUrl don't give you the real path... in this case, replace the ResolveUrl method to MapPath method.

e.g:

MapPath("~/games/alien.jpg"). The file will be uploaded to the location of '~'.


Got it?

Different between web application and windows application

Obviously, by the name itself web application is built for web and can be viewed by internet browser. Whereas windows application is a program that runs under windows. People choose web application because web app can relatively easy to deloy and once deloy it is readily widely available to anywhere and anytime. The design itself is distrbuted and programmers do not need to worry so much about complicated deloyment consideration. Sometimes, programmers choose to write in windows application is because somethings cannot be possibly done by having web application. For example, extensive use of processing power such as graphic randering program, e.g 3D designer program. A special program that deals with hardware such as printer driver, have to be written in windows application. Usually "designer program" oftens built as windows application. Whereas business application that requires multi users such as inventory system is oftenly built as web application.

If you are unsure of which is the best choice to go with, please follow my guildline, -

first think of if the program can be easily built and deployed by having web application, if the answer meet these criteria, then go for web application.

Otherwise go for windows application. or perhaps a combination of web and windows which known as smart application which combinethe best of both.

As my own preference, i like web application because it is relatively easy to manage the communication between modules and because it support css which makes styling much easier and faster.

I had been building windows application by using the composite application block CAB... The framework is cool but deployment can be much hassle because you have to worry the security issues ( you do not want your files be hacked by the user because he got your files).

Last but not least, go for web if possible for business realated appplication.

Post me a comment if you are disaggree with me :)

Monday, February 4, 2008

Split camel casing using regex .NET

ever wonder any better apporoch to convert "BeMyLover" to "Be My Lover"? Here the function in C#.


private string SplitCamelCasing(string input)
{
string output =
"";
return output =
System.Text.RegularExpressions.Regex.Replace(
input,
"([A-Z])",
"
$1",
System.Text.RegularExpressions.RegexOptions.Compiled).Trim();
}

Sunday, February 3, 2008

An easy way to manipulate database using Subsonic

I had been using various tools to manipulate database. The only tool that i find very simple so far .net web development is subsonic. http://www.subsonicproject.com/.

Subsonic is really powerful to CRUD your database. SQL is not nessary and it is all object oriented. The best object realtional mapper for .net 2.0

Give a try :)

Thursday, January 17, 2008

dropdownlist postback problem ASP.NET

have you encounter that ASP.NET dropdownlist control have a problem of persistent the data in the items list after you had make a postback? The problem is actually you have disabled the EnableViewState. Therefore the control will not persist any data after an postback. To enable it back, just - EnableViewState="true".

This is a super tips, because you might disabled it, in this case turn it on!

Thursday, November 29, 2007

Export table and data using SqlBulkCopy

i have one database to be exported and i try to use the import and export features from the sqlserver 2005. However i enconter one problem which is the primary key of the enabled indentity insert is all mess up after the importing to my new database. I just found and tested a utility and it works quite well.


method to export

generate a sql script with having the sql schema
use this program simple sql bulk copy downloadable from http://projects.c3o.com/files/default.aspx


ref:

http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx

Sunday, October 14, 2007

What programming language is the best?

Every programmer will ask this very common question What programming language is the best? C#? Java? C++? C? Perl? or ...??? In order to answer this question, you have to ask yourself what programming language you like most. Next, think about does the language powerful enough to be used in the type of application your are doing. Finally, some language is designed specifically and targeted to certain type of application. If the type of application you are doing match the language you are using, development productivity will improve and it is more easier to program. Likewise, you will get crazy in the middle of development if you choose the wrong language. For me, I want simple and powerfully high level language... I believe C# and it is my only choice.