Archive for May, 2008

Well, you can use AppSettings and ConnectionStrings from a Web.config file into your class library. You might be thinking why should I use these objects from a web.config where as I already have App.config file resides in a C# class library. Well, the reason is, you might face some requirements like you want to create General APIs from class library and that can be used in a Website in which you allow user to provide its connection string and some app settings that will be used by this APIs. In this case end user will provide its connection string and all other settings in web.config file of his website. (No doubt, you need to provide static names of “Keys” that this library is using, so that your application runs smooth)

Now comming to the point; you can access AppSettings and ConnectionStrings objects by adding reference of System.Configuration.dll from .NET framework into your C# library Reference and include that namespace in your class file at the beggening like:

using System.Configuration;

Whether you found this article useful or not? please provide your valuable comments.

Advertisements

When I faced this problem, I hardly find proper solution on net (May be my search keywords are not capable of finding proper solution). So, I decided to let everybody know how we can use HttpContext and Server.MapPath in a C# class library. You can also use Session, and Application State, Server, Request and Response objects by just adding reference of System.Web.dll from .NET framework into your C# library Reference and include that namespace in your class file at the beginning like:

using System.Web;

Whether you found this article useful or not? please provide your valuable comments.

I don’t want to post this article as this javascript is using ActiveX object and nowadays in latest browsers it will ask for user permission to access ActiveX object. Sometimes it may happen that browser does not support ActiveX object or it is disabled, at that time this code is of no use.

This code is for those people who are using ActiveX object and knows that browser will defiantly support the below script. May be it is useful to someone like me.

<script language=”javascript” type=”text/javascript”>

    var objFSO ;

 

    try

    {

        objFSO = new ActiveXObject(“Scripting.FileSystemObject”);

    }

    catch(err)

    {

        alert(err.message);

        alert(err.number);

    }

 

    function CheckExtention(el) // pass Upload File object’s ClientID here

    {

 

        var myel= document.getElementById(el);

        var file;

        var path = myel.value;

        //alert(path);

        file = objFSO.getFile(path);

        var size;

        size = file.size ; // This size will be in Bytes

  // We are converting it to KB as below

        alert(‘File Size is : ‘ + file.size /1024 +‘ KB’);

    }

 

</script>

 

Have you heard SubSonic?
No?

Then let me tell you something related to it first.

SubSonic is a Code Generator tool available with source code and its FREE. It works like your DAL (Data Access Layer) and generates code accordingly. It also provides its own library to create and implement Query, View and Stored Procedure. SubSonic comes with source code, so you can also make your own functions and methods as per your requirement and can use it.

What is SubSonic?
A Super High-fidelity Batman Utility Belt. SubSonic works up your DAL for you, throws in some much-needed utility functions, and generally speeds along your dev cycle.

Why SubSonic?
Because you need to spend more time with your friends, family, dog, bird, cat… whatever. You work too much. Coding doesn’t need to be complicated and time-consuming.

What do I need?
Something else to do – you’re about to save a bunch of time. SubSonic support SQL Server 2000 or 2005, MySQL, or Oracle (with SQLLite, SQLCE, and PostGres coming soon!)

you will find all the information related to SubSonic on http://subsonicproject.com/

Implementing Collation using SubSonic
I have implemented collation for SubSonic. And for that you first need to have source code for SubSonic. You need to change its source code to allow SubSonic implement collation. I have successfully implemented collation for Aggregate methods/functions like GetMin(), GetMax(), ExecuteAggregate(), OrderBy Asc(), and OrderBy Desc(). All these methods are available in SubSonic source code library and I have just added my code to implement collation.

If you have any kind of requirements like implementing Collation using SubSonic and want code for implementation then you can contact me on hemang.pandya@hotmail.com

Cheers…