The Best way to handle null in C# - Use Null Coalescing Operator. You have seen some samples where I have used ?? operator, that is nothing but a "Null Coalescing Operator"
Null Coalescing Operator or ?? Operator in C# is supported in Visual Studio 2005, 2008, and 2010.
The Null Coalescing Operator or ?? operator returns the left-hand operand if it is not null, or else it returns the right operand.
string strData;
strData = rsDB("FieldName").ToString() ?? "No Data";
strData will get value "No Data" in case of rsDB("FieldName") is null.
Enjoy Green coding @ www.Code4Green.com
Monday, June 13, 2011
Tuesday, May 24, 2011
The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.
If you are getting the following error while Attaching a EventHandler on a Sharepoint List, than follow these three steps to resolve that issue..
Error: The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.
Solution: Add the following Lines in you List Update code:
1. SPSecurity.RunWithElevatedPrivileges(delegate(){ - See Line 01
2. Add site.RootWeb.AllowUnsafeUpdates = true; , See Line 04
3. Add site.WebApplication.FormDigestSettings.Enabled = false;, See line 10
Sample Code
SPSecurity.RunWithElevatedPrivileges(delegate(){
using (SPSite site = new SPSite(URL))
{
site.RootWeb.AllowUnsafeUpdates = true;
using (SPWeb siteWeb = site.OpenWeb())
{
SPList list = siteWeb.Lists["TestList"];
SPEventReceiverDefinition defItemAdding = list.EventReceivers.Add();
site.WebApplication.FormDigestSettings.Enabled = false;
defItemAdding.Assembly = "WSPBuilderProject1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e0a58138cf93116a";
defItemAdding.Class = "WSPBuilderProject1.TestListEH";
defItemAdding.Name = "AddingEventHandler";
defItemAdding.Type = SPEventReceiverType.ItemAdding;
defItemAdding.SequenceNumber = 1001;
//defItemAdding.Synchronization = SPEventReceiverSynchronization.Synchronous;
defItemAdding.Update();
site.WebApplication.FormDigestSettings.Enabled = true;
}
site.RootWeb.AllowUnsafeUpdates = false;
}
});
Enjoy Sharepoint Green Coding @ Code4Green.com
Error: The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.
Solution: Add the following Lines in you List Update code:
1. SPSecurity.RunWithElevatedPrivileges(delegate(){ - See Line 01
2. Add site.RootWeb.AllowUnsafeUpdates = true; , See Line 04
3. Add site.WebApplication.FormDigestSettings.Enabled = false;, See line 10
Sample Code
SPSecurity.RunWithElevatedPrivileges(delegate(){
using (SPSite site = new SPSite(URL))
{
site.RootWeb.AllowUnsafeUpdates = true;
using (SPWeb siteWeb = site.OpenWeb())
{
SPList list = siteWeb.Lists["TestList"];
SPEventReceiverDefinition defItemAdding = list.EventReceivers.Add();
site.WebApplication.FormDigestSettings.Enabled = false;
defItemAdding.Assembly = "WSPBuilderProject1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e0a58138cf93116a";
defItemAdding.Class = "WSPBuilderProject1.TestListEH";
defItemAdding.Name = "AddingEventHandler";
defItemAdding.Type = SPEventReceiverType.ItemAdding;
defItemAdding.SequenceNumber = 1001;
//defItemAdding.Synchronization = SPEventReceiverSynchronization.Synchronous;
defItemAdding.Update();
site.WebApplication.FormDigestSettings.Enabled = true;
}
site.RootWeb.AllowUnsafeUpdates = false;
}
});
Enjoy Sharepoint Green Coding @ Code4Green.com
Tuesday, May 3, 2011
How To Add Windows Live Messanger in your website?

If you know HTML, than you can do this easily, just follow these 12 steps and see these steps in attached screen shot. I am sure on the 12th step, you will see the miracle... :)
1. Login to http://login.live.com with you live/hotmail/msn email id
2. go to setting page Windows Live Setting
3. click on WebSetting link in left side menu
4. Select checkbox for " Allow anyone on the web to see my presence and send me messages."
5. Click Save button on top of the page
6. Click on Create HTML link in left side menu
7. Choose which control you want to display on your page. It has three options
7.1 - IM window - It embed the messanger as a frame. It will allow chating within your site's page. This will give you the option to
select height, width and theme color for your messanger.
7.2 - Button - Show button with current status of messanger. This will launch the web based windows IM in new window.
7.3 - Status Icon -> This will show only status icon of your messanger's status. This will launch the web based windows IM in new
window.
NOTE: Step 7.1, and 7.2 will open a new page with the following url with your Live Invite Id as invitee:
http://settings.messenger.live.com/Conversation/IMMe.aspx?invitee=bd72eb1303b8b293@apps.messenger.live.com&mkt=en-CA
8. After selecting the option in step 7, it will generate the html and display in textbox next to label "Copy the HTML and paste it into
your webpage"
8.1. copy and paste html in your html or asp.net page and run it.
9. Once you will run your page, than it will ask a visitor to begin conversation. Click on Begin Conversation link.
10. Onclick over Begin Conversation, it will popup a window to type visitor's name. So type your name here and hit OK button.
11. After entering your name as visitor, system will popup Captcha screen, enter the characters shown on the image 2gNC3V0g and click on
submit button.
12. Now you are ready to chat, start doing chating.
Enjoy your green code @code4green.com
1. Login to http://login.live.com with you live/hotmail/msn email id
2. go to setting page Windows Live Setting
3. click on WebSetting link in left side menu
4. Select checkbox for " Allow anyone on the web to see my presence and send me messages."
5. Click Save button on top of the page
6. Click on Create HTML link in left side menu
7. Choose which control you want to display on your page. It has three options
7.1 - IM window - It embed the messanger as a frame. It will allow chating within your site's page. This will give you the option to
select height, width and theme color for your messanger.
7.2 - Button - Show button with current status of messanger. This will launch the web based windows IM in new window.
7.3 - Status Icon -> This will show only status icon of your messanger's status. This will launch the web based windows IM in new
window.
NOTE: Step 7.1, and 7.2 will open a new page with the following url with your Live Invite Id as invitee:
http://settings.messenger.live.com/Conversation/IMMe.aspx?invitee=bd72eb1303b8b293@apps.messenger.live.com&mkt=en-CA
8. After selecting the option in step 7, it will generate the html and display in textbox next to label "Copy the HTML and paste it into
your webpage"
8.1. copy and paste html in your html or asp.net page and run it.
9. Once you will run your page, than it will ask a visitor to begin conversation. Click on Begin Conversation link.
10. Onclick over Begin Conversation, it will popup a window to type visitor's name. So type your name here and hit OK button.
11. After entering your name as visitor, system will popup Captcha screen, enter the characters shown on the image 2gNC3V0g and click on
submit button.
12. Now you are ready to chat, start doing chating.
Enjoy your green code @code4green.com
Thursday, April 28, 2011
Create a new SharePoint column in User Profile's list

How to get a hidden Sharepoint List for User Profile?
Here is the way to find out hidden user profile's list in sharepoint: At the top level site in site collection, type this url: /_catalogs/users/simple.aspx , that will give you User Information List's default view.
Here is the way to find out hidden user profile's list in sharepoint: At the top level site in site collection, type this url: /_catalogs/users/simple.aspx , that will give you User Information List's default view.
Go and edit this page(site action >> edit page), and than modifiy Shared webpart. It will give list view of this list, edit the current view. Edit will show the editable view of that user Profile's hidden list.
Now you got the place where you can see all the column from this hidden treasure, now it is the time to add a new column in this list, so you can use this column in your custom permission's code:
Here is the PowerShell to Create a New Coloumn in hidden site collection level's "User Information List"
[system.reflection.assembly]::loadwithpartialname("microsoft.sharepoint")
$site= New-Object Microsoft.SharePoint.SPSite ("http://YourSiteName")
$web=$site.OpenWeb()
$list=$web.Lists["User Information List"]
$list.Fields.Add("Region1", "Text", 0)
$site= New-Object Microsoft.SharePoint.SPSite ("http://YourSiteName")
$web=$site.OpenWeb()
$list=$web.Lists["User Information List"]
$list.Fields.Add("Region1", "Text", 0)
Tuesday, April 19, 2011
WebMatrix - New Buzzword in IT Industry
WebMatrix is a free tool that allows you to create, customize and publish websites, Believe me It’s amazingly easy to use.
WebMatrix connects you to a world of popular and free open-source Web applications, including WordPress, DotNetNuke, Umbraco, Joomla!, Moodle, Drupal , and many more(till now 49 apps). You can select a website from built-in gallery, and WebMatrix will handle all the downloading and installation of your new Web site.
Here is the list of Features of WebMatrix which makes it very powerful and #1 development tool for the web development.
Features List of WebMatrix
WebMatrix connects you to a world of popular and free open-source Web applications, including WordPress, DotNetNuke, Umbraco, Joomla!, Moodle, Drupal , and many more(till now 49 apps). You can select a website from built-in gallery, and WebMatrix will handle all the downloading and installation of your new Web site.
Here is the list of Features of WebMatrix which makes it very powerful and #1 development tool for the web development.
Features List of WebMatrix
- Small, but complete package - It is free web development tool. It is small in size but very powerful tool.
- Desktop based Web Development and Testing Environment - You will get the same powerful Web server(IIS Express), database engine(SQL CE4), and frameworks(MVC 3.0) that your Web site on the internet uses. This ensures that your transition from development to production is smooth and seamless.
- Easy to Code - Start with HTML, CSS and JavaScript and then seamlessly connect to a database or add in dynamic server code using the new ‘Razor’ syntax for ASP.NET Web pages.
- Webmatrix have intellisense - it also supports tag completion and hinting for standard HTML and CSS markup making it easier and faster for you to write code.
- Simple Publishing - You can find host company to suite your need. Use webMatrix to find your web host which supports webmatrix.
- Easy to cross bowser testing - You can test your site directly will diffrent browsers using webmartix tool.
- Last but not least - It will connect you with lots of open source web applications(till the date i am writing this blog - 49 applications incliding most populars WordPress, DotNetNuke, Umbraco, Joomla!, Moodle, Drupal and more)
- Make your site More Search engine friendly - Run an SEO report and find how to make your site more visible to search engines.
- Code Helper is the best helping tool - Want to display a Twitter feed? Need to show a video? Code helpers make common tasks easy to do with just a simple tag in your HTML(Yes it is HTML not server side...).
- Nice Interface with IDE, Database, IIS, FTP, and more - WebMatrix has rich code editor, a database editor, Web server management, Search Engine Optimization, FTP publishing, and many more..
- Easy and Lightweight Database - Using a database has never been easier! WebMatrix includes a small, embedded database SQL Server CE 4. Copy that database from your machine to web server under bin folder and you are done.
Enjoy your Green coding @ code4Green.com
Thursday, April 14, 2011
Compare powershell and STSAdm commands for SharePoint

Here is the Most important STSAdm commands which is used in Sharepoint 2007 for scripting. I have converted those comands into PowerShell, so you can compare and use it. Here is the sample to compare side by side STSAdm and PowerShell commands for Sharepoint:
- STSAdm Command
- stsadm –o addsolution –filename “D:\Temp\YourSharePointSolution.wsp“
- stsadm –o deploysolution –name YourSharePointSolution.wsp –url http://myspwebappp –allowgacdeployment –immediate
- stsadm –o upgradesolution –name YourSharePointSolution.wsp –filename “D:\Temp\YourSharePointSolution.wsp” -immediate
- stsadm –o retractsolution –name YourSharePointSolution.wsp –url http://myspwebapp –immediate
- stsadm –o deletesolution –name YourSharePointSolution.wsp
- stsadm –o activatefeature –name YourFeatureName –url http://YourSharePointWebApp
- stsadm –o deactivatefeature –name YourFeatureName –url http://YourSharePointWebApp
- stsadm -o execadmsvcjobs
- stsadm -o userrole -userlogin "YourUserOrGroupName" -role "Approve" -add -url "http:/YourSPSite"
- PowerShell Command
- Add-SPSolution “D:\Temp\YourSharePointSolution.wsp“
- Install-SPSolution –Identity YourSharePointSolution.wsp –WebApplication http://myspwebapp –GACDeployment
- Update-SPSolution –Identity YourSharePointSolution.wsp –LiteralPath “D:\Temp\YourSharePointSolution.wsp” –GacDeployment
- Uninstall-SPSolution –Identity YourSharePointSolution.wsp –WebApplication http://myspwebapp
- Remove-SPSolution–Identity YourSharePointSolution.wsp
- Enable-SPFeature –Identity YourFeatureNameOrGuid –url http://YourSharePointWebApp
- Disable-SPFeature –Identity YourFeatureNameOrGuid –url http://YourSharePointWebApp
- Start-SPAdminJob -Verbose
- New-SPUser – UserAlias ‘YourUserOrGroupName’–displayname ‘Your Display Name’ –web YourSPSite
Here is the complete list of stsadm command and their related PowerShell command: Click HERE
Thursday, April 7, 2011
Generate Test Data - VB.net Class For Test Data Generation
Here is the VB.net code to generate your test data
Download VB.net Code project Enjoy Green Coding @ Code4Green.com
Subscribe to:
Posts (Atom)