Wednesday, September 28, 2011
Simple Extension Methods: C# Programming
1. Create a namespace for the extension methods. (i.e. ExtensionMethods)
2. Cteate a class. (i.e. MyExtensions)
3. Now create the extension methods in the class.
Here, we are extending string type to have a new extension method 'WordCount':
using System;
using System.Text;
namespace ExtensionMethods
{
public static class MyExtensions
{
public static int WordCount(this String str)
{
return str.Split(new char[] { ' ', '.', '?' }, StringSplitOptions.RemoveEmptyEntries).Length;
}
}
}
4. Now, lets use this extension method:
using System;
using ExtensionMethods;
namespace ThreadTest
{
class Program
{
static void Main(string[] args)
{
string str = "You are rocking";
Console.WriteLine(str.WordCount());
}
}
}
5. That's it. Happy coding.
Wednesday, August 10, 2011
Tuesday, June 21, 2011
Findout the recently modified objects in sql database
FROM sys.objects
WHERE type = 'P'
order by modify_date desc
Monday, June 20, 2011
Find a string in all Stored Procedures
SELECT OBJECT_NAME(id)
FROM syscomments
WHERE [text] LIKE '%foobar%'
AND OBJECTPROPERTY(id, 'IsProcedure') = 1
GROUP BY OBJECT_NAME(id)
Wednesday, March 23, 2011
Send mail from asp.net
public class MailHelper
{
public static void SendMailMessage(string from, string to, string bcc, string cc, string subject, string body)
{
MailMessage mMailMessage = new MailMessage();
mMailMessage.From = new MailAddress(from);
mMailMessage.To.Add(new MailAddress(to));
if (!(string.IsNullOrEmpty(bcc)))
{
mMailMessage.Bcc.Add(new MailAddress(bcc));
}
if (string.IsNullOrEmpty(cc))
{
mMailMessage.CC.Add(new MailAddress(cc));
}
mMailMessage.Subject = subject;
mMailMessage.Body = body;
mMailMessage.IsBodyHtml = true;
mMailMessage.Priority = MailPriority.Normal;
// Instantiate a new instance of SmtpClient
SmtpClient ss = new SmtpClient();
//ss.EnableSsl = true;
ss.Timeout = 10000;
ss.DeliveryMethod = SmtpDeliveryMethod.Network;
mMailMessage.BodyEncoding = UTF8Encoding.UTF8;
mMailMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
ss.Send(mMailMessage);
}
2. Add the following smtp configuration in Web.config file.
Wednesday, March 16, 2011
My system is damn slow, what to do?
1. RacTask : Microsoft Reliability Analysis task to process system reliability data.
If you want to speed up your task rather than this analysis, diable this task in TaskScheduler.
Task Scheduler > Task Scheduler Library > Microsoft > Windows > RAC > RacTask > right click > disable
2.
Tuesday, February 1, 2011
Session state can only be used when enableSessionState is set to true
Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that system.Web.SessionStateModule or a custom session statemodule is included in the
One possible solution - Set the startup page in your website.
Sunday, January 30, 2011
Some Googling tricks
Type "intitle:indes of" abc
abc can be replaced by anthing like: hack pdf OR abobe OR akon mp3
Now, browse the links in search result page and download if you find something interesting.
2. Go to www.google.com
Type inurl:"viewerframe?mode=refresh"
3. Go to www.google.com
Type intext:"UAA(MSB)" Lexmark-ext.pdf
4. Type elgoog
5. inurl:/view/index.shtml
spy the database sp changes
FROM sys.objects
WHERE type = 'P'
order by modify_date desc
Tuesday, January 18, 2011
Find out, why the net is so slow?
- Type cmd in your Windows Run box.
- Type "netstat -b 5 > activity.txt" and press enter.
- After say 2 minutes, press Ctrl+C.
- Type "activity.txt" on the command line to open the log file in notepad
Sunday, November 28, 2010
Why WCF RIA Services?
1. To provide best user experience the client application should be aware of business logic at server-side, WCF RIA service solves this problem by providing framework components, tools, and services that make the server-side application logic available to the RIA client without requiring you to manually duplicate the business layer programming logic at presentation layer.
2. RIA Client application always gets latest business rules as it get compiled.
3. RIA Services adds tools to Visual Studio that enable linking Client project(Silverlight) and Server project(Asp.net) in a single solution and generating code for the Client project from the middle-tier code.
4. The framework components support prescriptive patterns for writing application logic so that it can be reused on the presentation tier.
5. Domain Service - In RIA Services, you expose data from the Server project to Client project by adding domain services. Here, each domain service gets implemented as WCF Service.
Monday, August 30, 2010
Silverlight Animation
There are 4 type of Key Frames here:
1. Linear : Moves from the starting state to the end state in a smooth, linear fashion.
2. Discrete : Jumps from starting state to end state instantaneously.
3. Spline : Moves from the starting state to the end state varying speed based on mathematically defined curve.
4. Easing : A more evolved version of Spline, moves from the starting state to the end state based on a easing funcation.
Wednesday, April 14, 2010
Friday, January 8, 2010
Report Viewer not working in dev server (the + sign for grouping is not coming, rather a red X image coming)
Error msg : 'RSClientController' is undefined .....
'ClientControllerReportViewer1' is null or is not an object.
What's odd is - it appears the report actually runs despite the javascript errors, but the resulting report has the red "X"s on the image tags in the control itself and the report returns no data.
Soln :
1. The .axd extension in the application config in IIS should set to use framework 2.0 instead of 1.1
2. If the 1st soln is not working,
Click on the application virtual directory in IIS7 and click on the 'Handler Mappings' section. Then 'Add Managed Handler'
Request path: Reserved.ReportViewerWebControl.axd
Type: Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Name: Reserved.ReportViewerWebControl.axd
Once this was created, it worked fine in the Integraded mode AppPool.
3. Just add the following line to my web.config (it should get added automatically, but if not then ..)
4. If still not working !
- then, I have to see the code, post me that.
Thursday, October 29, 2009
Interfaces for collections classes - System.Collection
Generic collection classes are in - System.Collection.Generic
Specific Collection classes are in - System.Collection.Specialized
Generic interfaces:-
1. IEnumerable<T> - derives from IEnumerable interface
2. ICollection<T>
3. IList<T> - derives form ICollection interface
allows to access the collection with indexer
4. IDictionary<T>
5. ILookup<T>
6. IComparer<&>
7. IEqualityComparer<T>
Non-Generic versions of interfaces:-
1. IEnumerable - required if a foreach statement is used with the collection
2. ICollection
3. IList - derives form ICollection interface
allows to access the collection with indexer
4. IDictionary - implemented by ICollection interface
has key and value pair