Wednesday, April 29, 2009

Read xml from web page and bind the data to Silverlight module.

Some times we have requirements in SharePoint that we need to pull images from SharePoint library and display those images in Silverlight module with rich UI. But we know that Silverlight runs on client side, we can't access the SharePoint libraries in the Silverlight projects because of permission issues as well.
So, here we build an architecture that SharePoint will build the XML for us and write it on the page and Silverlight grabs the XML from the page and displays the images on the UI. How nice it is. You can get the first part i.e. get xml (image) data from the SharePoint libraries here.

Here, we are discussing about the code we need to place in Page.xaml.cs file to read xml from web page.
public Page()
{
string controlid = "divImgs"; //You can also use intiparams of Silverlight params to get the id.
InitializeComponent();

string xmlstring = string.Empty;
if (controlid != null)
{
HtmlElement ctl = HtmlPage.Document.GetElementById(controlid);
if (ctl != null)
xmlstring = (string)ctl.GetProperty("innerHTML");
}

if (!string.IsNullOrEmpty(xmlstring))
{
ProcessXML(xmlstring);
}
}
The above code is the Page constructor of the Page. Xaml.cs file.
1. Here, we are catching the control on the HTML document and reading it's HTML. if you remember, while coverting the data view web part data from HTML to XML, in the XSLT i assigned an id for a html tag called "divImgs". We are using this id here in the cs file, and reading the HTML, obviously it will get the xml data to the xmlstring variable.
2. No, we need to process the XML and bind the data to the silverlight control. This is why i am calling a function called "Process XML".
private void ProcessXML(string xml)
{
images = new List<string>();
if (xml != string.Empty)
{
try
{
StringReader textStream = null;
textStream = new StringReader(xml);

if (textStream != null)
{
using (XmlReader reader = XmlReader.Create(textStream))
{
while (!reader.EOF)
{
if ((reader.IsStartElement()) && (reader.LocalName == "slides"))
{
if (reader.HasAttributes)
{
reader.MoveToAttribute("baseUrl");
}
}
else
{
if ((reader.LocalName == "slide") && (reader.HasAttributes))
{
reader.MoveToAttribute("imageUrl");
string imageName = reader.Value.ToLower();
if ((imageName.Contains(".jpg")
|| imageName.Contains(".png")))
images.Add(reader.Value);
}

}
reader.Read();
}
}
}
}
catch (Exception ex)
{
}
}
}
3. In the above code, images is the global variable of type List<string>. We are filling this object with the image urls by reading the xml string.
4. Now by calling the ProcessXML function, we are done with getting image urls. So we have collection of image urls, and use this object to give input as the Silverlight module controls and display on the UI.

Very simple and nice.
Happy coding!!!

Show images in Silverlight by reading images from SharePoint library

Hi,
Silverlight works on client side, so it's not possible to add SharePoint libraries in Silverlight project. But we have a way that we can access SharePoint data and show it up in Silverlight in SharePoint site.
We have a requirement where we need to pull data from the SharePoint libraries and lists and show the data in Silverlight. Here i will explain a scenario where we can pull the images from image library and show it in Silverlight.

Follow the steps below to do this.
Get data from SharePoint library and make it in the form of XML.
  1. Go to the page where we want to show the Silverlight module on the site or create a new page.
  2. Open the page in SharePoint designer.
  3. Add a data view web part to the page some where in web part zone.
  4. Select the data source library from Task Pane menu.
  5. Select the library/list from the data source library where your images are present.
  6. Click on the library and select Show Data.
  7. Select the columns, which refer the Title, Image Path etc you want to show in Silverlight from Data Source details task pane.
  8. Select the option Insert select fields as "Multiple item view". So now our data view web part is filled with the data. [If you want apply some properties like show images in asc order etc..]
  9. After selected the columns, apply a filter to get only images from the library/lists. we can do this by selecting the filters option from the data view web part.
  10. Here, select the image title or url column in the field name, in comparison select contains and here enter valid formats Silverlight allows in the value field.
  11. Save the page and open it in the browser [IE].
  12. Till now what we did is, we are getting the data from the SharePoint library/Lists and showing up it in the data view web part and it renders as a table.
  13. Now, we need to change the XSLT of the data view web part to get the table format of data as the XML format. We have XSLT, so we can easily do that.
  14. Add the below XSLT code to the data view web part by going to edit for the web part and modify settings --> XSL editor.
  15. Remove text in the editor and add this code.

  16. If you observe i am pulling some values from the data view and making xml.
  17. Now, when you save the web part and see the page, you can't see anything in the data view web part, because now your data is in the format of xml.
  18. You can see this by doing view source and search for "
  19. We are done with part 1 now. i.e. getting data from SharePoint library. Now we will move to second part.
Get XML from the page and give that as input to Silverlight module:
At this point, we got the xml i.e. xml is on the page, now we need to read the xml from the page in the silverlight project and display the images as we want by applying animations, styles etc..
You can see the part 2 here.


Monday, April 27, 2009

replace querystring with some value in javascript

In my project, i have a requirement that we need to get url from the browser and depends on user selection, or some criteria we need to change some querystring values and reload the page with new url. Here is a small function which will do that in javascript.
function replaceQueryString(url, param, value) {
var preURL = "";
var postURL = "";
var newURL = "";

var start = url.indexOf(param+"=");
if(start > -1)
{
var end = url.indexOf("=", start);
preURL=url.substring(0,end) +"="+value;

var startRest = url.indexOf("&",start);
postURL="";
if(startRest > -1)
{
postURL=url.substring(startRest);
}
}
else
{
var delimeter = "";
preURL=url;
if (url.indexOf("?") > 0)
delimeter = '&';
else
delimeter = '?';

postURL=delimeter+param+"="+value;
}
newURL = preURL+postURL;
var index = newURL.indexOf('id=',0);
if(index > -1)
{
var Nurl = newURL.substring(0,index);
var EUrl = newURL.substr(index,newURL.length - index);
var eIndex = EUrl.indexOf('&',0);
if(eIndex > -1)
EUrl = EUrl.substr(eIndex, EUrl.length - eIndex);
//newURL = newURL.substring();
newURL = Nurl + EUrl;
}
return newURL;
}   
the newUrl which builds the new url with updated querystring values.

mozilla frefox enter button problem in asp.net.

i am facing a small problem, which ate my mind almost 10 hours.
Introduction:
I am using Updatepanel [Ajax] in my site. According to my client specification, in which panel or div cursor focus on, when he/her press enter, the corresponding panel button click event will fire and request goes to server and gives response.
i am using control on my pages, because it has the property called DefaultButton. So, this will work perfectly for me if and only if, user browse my site in IE. then what about Mozilla?
Here my problem starts…
Problem:
1. The DefaultButton property of the Panel/Form won’t work in Mozilla when you hit enter key, when all these panels are reside in UpdatePanel control.
2. When any one press Enter button, it should check for validation if any input controls are there in that panel.
Solution:
After a long research i wrote small java script function to solve the problem.
OnClientClick=”setDefaultButton(this.name);
Java script function:
function setDefaultButton(name)
{
Page_ClientValidate();
if(document.all)
{}
else
{
if(!Page_IsValid)
__doPostBack(name,"");
}
}
if you have any issues with my code, please let me know.

To access html control without runat=”server” in C# code.

In ASP.NET coding, I don't think it is needed to create or declare only ASP.NET server-side controls. Some cases, to make our page more efficient and faster we can write HTML controls by adding runat="server" to access them on server side code [C#].

But, there are some special requirements where we need to create HTML controls dynamically in c# and add them in a string and write the string to a page. And whenever some event raised like button click event, on server side code, we need to retrieve the values of those HTML controls. As it is not declared as runat="server" on the page, we can't take the values very simple. In that type of scenarios, this solution works. Please follow the solution below to get the values of the HTML controls which doesn't have runat="server" attribute defined.

Example:
HTML declaration:
<input type="text" name="txtName" />

C# Code:
string strValue = Page.Request.Form["name of the control"].ToString();

Note:
To get the values in server side code of HTML control, we need to follow below points.
  • The tag should have an attribute called NAME. Because it is used as key in form[].
  • The form method should be of type POST.
That's it!!! Please let me know, if you have any issues with this approach. Hope this helps...

Conditional Statement example in SharePoint workflow.

In SharePoint workflow, when we are using the if/else activities, the if/ else methods contains Event argument called ConditionalEventArgs.
if you set e.Result=true, then if block will executes,
if you set e.Result=false, then else block will executes.

private void IfMethod(object sender, ConditionalEventArgs e)

{

if (isTrue)

e.Result = true;

else

e.Result = false;

}

private void ElseMethod(object sender, ConditionalEventArgs e)

{

if (!isTrue)

e.Result = true;

else

e.Result = false;

}

depending on the boolean variable “isTrue”, the if/else blocks will executes…
In the above case, i am setting “isTrue” variable depending on my logic, before calling if/else statements.
For while activity also, same logic applies.
if you set e.Result=true, it will iterate until you set e.Result=false.

Role of ItemMetadata.xml in Infopath forms [SharePoint workflow].

Introduction:

ItemMetadata.xml is the file used to store/transfer the data from one Infopath to another. The name of the file is case - sensitive.

For example, in a sharepoint workflow, there are 10 steps, in each step we are using infopath and we want send some information from one to the next infopath form, the information won't save any where. we need to tell explicitly to infopath to store in xml file. that is nothing but ItemMetadata.xml.

It acts as the secondary data source to the infopath.

To compensate for the possibility of schema differences between the task data and the form it only stores the schema instead of data.

Example schema is

<z:row xmlns:z="#RowsetSchema" ows_fieldname=""/>

Note: Every field name should be prefixed with ows

In programming, we can retrieve the data from info path using the property called ExtendedProperties.

afterProperties.ExtendedProperties["filedName"].ToString();

Creating new instance of SharePoint workflow through C# code.

In SharePoint 2007, very good feature I like much is that framework supports for writing custom events, features, workflows or any other stuff... We can customize complete SharePoint system at any context.
While working with SharePoint custom workflows, we get some scenarios where we need to stop a workflow or start a new instance of workflow through coding. So, I did some research on the MSDN library and saw all the dll's by doing some reflection on the libraries and found some functions and classes which supports this.

Here, I want to present a small code snippet which does terminating currently running wokflow and start a new instance of the workflow on the same list item.
SPListItem listItem = workflowProperties.Item;
SPList spList = workflowProperties.List;
string initData = workflowProperties.InitiationData;

const string WF_GUID = “The GUID of workflow template”;
workflowProperties.Site.WorkflowManager.RemoveWorkflowFromListItem(workflowProperties.Workflow);
workflowProperties.Site.WorkflowManager.Dispose();

SPWorkflowAssociation associationTemplate= spList.WorkflowAssociations.GetAssociationByBaseID(new Guid(WF_GUID));

workflowProperties.Site.WorkflowManager.StartWorkflow(listItem, associationTemplate, initData);

Hope this will give you a good start to code on SharePoint workflow start and terminate through coding. Let me know, what you think.

How to give anonymous access to the reports.

In some organizations we must have some requirements where we need to show reports to all users. In those cases we might need to enable anonymous access to the reports. Below are the steps which we must follow to enable anonymous access to reports in SSRS

Changes in IIS:
  1. Go to IIS.
  2. Select reports application –> properties –> Directory Security –> Authentication and Access control –> Edit –> Enable Anonymous access.
Changes in SSRS Application:
  1. Open the reports on the report server located at http://<servername>/reports
  2. Browse to the report that needs to be accessed anonymously.
  3. Select properties tab for the report.
  4. Select security from the left navigation.
  5. Select New Role Assignment from this page.
    1. Give a group name - everyone (in the "group or user name" text box).
    2. Select the option Browser role and then click OK. [Browser role is for READ - ONLY access].

How to display Site pages/ Subsites in navigation using Treeview control in sharepoint applicartion.

For very big projects in SharePoint or any other platform it's very difficult to organize the navigation to keep all the data on page. For example, you have plenty of data around 15 to 20 subsites and 50 pages, then it's impossible to display all the links at one place. So, it's big challenge that even you have more data on site but if user failed to find what he want on the site then it's just waste. So by thinking that for a long time, I came up with a good solution and here I am presenting for you with code.

What is my goal?
I want to show all the sites and pages in a SharePoint site in navigation area [lefft navigation] using asp tree view control in SharePoint.

Below is the complete code of the treeview functionality
In my case, we have 3 levels of data. So used tree view that has 3 levels.

ASPX Code:
Treeview control declaration and it's tree nodes 3 levels. We are writing some server side code to get and render the data as we want using different conditions. So for this purpose I am using prerender event of the tree view control.

<asp:TreeView ID="treeviewLeftNav" runat="server"
Width="191px" HoverNodeStyle-CssClass="leftNavHover"
DataSourceID="SiteMapDS" SelectedNodeStyle-CssClass="leftNavSelected"
OnPreRender="ControlTreeView_OnPreRender"
<LevelStyles>
<asp:TreeNodeStyle CssClass="leftNav1"></asp:TreeNodeStyle>
<asp:TreeNodeStyle CssClass="leftNav2"></asp:TreeNodeStyle>
<asp:TreeNodeStyle CssClass="leftNav3"></asp:TreeNodeStyle>
</LevelStyles>
</asp:TreeView>

We are using publishing site with all features enabled. So we are using PublishingNavigation control with PortalSiteMapDataSource to pull all pages and sites from SharePoint site.

<PublishingNavigation:PortalSiteMapDataSource ID="SiteMapDS" Runat="server"
SiteMapProvider="CurrentNavSiteMapProvider" EnableViewState="true"
StartingNodeOffset="0" ShowStartingNode="False"
TrimNonCurrentTypes="Heading"/>

In c#, I wrote below code for exact functionality of Expand/collapse TreeView.
C# code:
void ControlTreeView_OnPreRender(object sender, EventArgs e)
{
foreach(TreeNode n in treeviewLeftNav.Nodes)
{
if(n.NavigateUrl == Request.Url.AbsolutePath)
n.Expand();
else
{
if(treeviewLeftNav.SelectedNode!=null)
{
if(n!=treeviewLeftNav.SelectedNode.Parent)
{
if(n.ChildNodes.Count>0)
n.Collapse();
}
}
else
{
treeviewLeftNav.CollapseAll();
break;
}
}
RenderTreeNodes(n);
}

if(treeviewLeftNav.SelectedNode!=null)
treeviewLeftNav.SelectedNode.Expand();
}

void RenderTreeNodes(TreeNode node)
{
if(node!=null)
{
if(node.ChildNodes.Count>0)
{
foreach(TreeNode n in node.ChildNodes)
{
if(n.NavigateUrl == Request.Url.AbsolutePath)
{
n.Expand();
}
else
{
if(n!=treeviewLeftNav.SelectedNode.Parent)
n.Collapse();
else
n.Parent.Expand();
}
}
}
}
}
Note: please change your web.config of the site to allow server side code in pages where you are writing server side code.

MOSS My Calendar web part login problem for different accounts.

Introduction
When i work with my calendar web part in SharePoint i got lot of questions and things happend. I configured every thing correctly in My Calendar web part. i.e. Mail server address, Mailbox.
But, when i open the page which contains calendar web part, it prompts for user name and password of SharePoint site and another for the Calendar login . i.e. login page of OWA application. If i provide the credentials it will work very fine.

Now the problem starts. If the same application is trying to access by another users, other than me then they always failed to login to my calendar web part. This is because, in mailbox i given my mail account, when others try to access the web part, it won't work at all. What they need at that time is they will edit the web part, and will change the mail box entry to their own email address. But this is not possible for all users because all users don't have access to edit page/web part.

My Calendar web part is not working for multiple users in SharePoint 2007. When you add the web part on a page, which mail entry you given in the Mail box that account only can login. I will tell you the reason behind it. My calender web part is developed only for the purpose of showing their calendar events on the my site page. My site usually have access to edit/delete etc for current logged in user, so he will see the content belongs to him. But as per my requirements i want to use the calendar on the site other than the my site pages.

Solution
To solve the above mentioned problem, i created a custom web part to work for any logged in user. You can get this code and build it, add the appsetting variables in the web.cofig and deploy it to your site, You can get the deploy instructions of web part in MSDN.

Web.Config changes:
We need to provide 2 inputs to the web part.
1. Site Url.
2. Exchange Server Url.

Requirements:
We have setup a job [Usually we will setup while installing SharePoint and configuring the SSP] in your SharePoint server Shared services Provider [SSP], to pull user accounts from the Active Directory to Sharepoint profile database. Because below code gets the emailid automatically from the user profile database depending on the logged in user. And places that emailid in Mail Box entry of the my calendar web part.

Usually, when we configure the Profile import, we will give source and configure the schedule too. i.e. Every day night or every week etc… it pulls data from given source [ex: Active directory] to profile database.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Portal.WebControls;
using Microsoft.SharePoint.Portal.Topology;
using Microsoft.SharePoint.Portal;
using Microsoft.SharePoint.Portal.UserProfiles;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;namespace MyCalendarWebPart
{
[Guid("15241046-2128-4a1d-b6d5-24c8a67c4d28")]
public class MyCalendarWebPart : Microsoft.SharePoint.WebPartPages.WebPart
{
private OWACalendarPart wpCalendar;
HtmlGenericControl litMsg = null;
HtmlGenericControl roundedCorner;

protected override void CreateChildControls()
{
wpCalendar = new OWACalendarPart();
litMsg = new HtmlGenericControl();
roundedCorner = new HtmlGenericControl();
roundedCorner.InnerHtml = “”;

Controls.Add(configureCalendar());
Controls.Add(litMsg);
Controls.Add(roundedCorner);

base.CreateChildControls();
}

private OWACalendarPart configureCalendar()
{
try
{
//Connect to the portal and get the portal context.
TopologyManager topology = new TopologyManager();
PortalSite portal = topology.PortalSites[new Uri(ConfigurationManager.AppSettings["SiteUrl"])];
PortalContext context = PortalApplication.GetContext(portal);

//initialize user profile config manager object
UserProfileManager profileManager = new UserProfileManager(context);
UserProfile profile = profileManager.GetUserProfile(true);

wpCalendar.Title = “My Calendar”;
wpCalendar.ViewName = “Weekly”;
wpCalendar.CssClass = “”;

// use the profile object to retrieve the properties you need in your company to
// retrieve the mail box name
string workmail = profile[PropertyConstants.WorkEmail].ToString();

wpCalendar.MailboxName = workmail;
wpCalendar.OWAServerAddressRoot = ConfigurationManager.AppSettings["ExchangeServerUrl"];

wpCalendar.Height = “655″;
wpCalendar.Width = “600″;
wpCalendar.ImportErrorMessage = “No EmailID found for your account.”;
}
catch
{
litMsg.InnerHtml = “No EmailID found for your account.“;
}

return wpCalendar;
}

protected override void RenderWebPart(HtmlTextWriter output)
{
try
{
wpCalendar.RenderControl(output);
litMsg.RenderControl(output);
roundedCorner.RenderControl(output);
}
catch (Exception ex)
{
output.Write(ex.ToString());
}
}

public override void RenderControl(HtmlTextWriter writer)
{
base.RenderControl(writer);
}
}
}

Note: In above code i am pulling site url and exchange server url from the appsettings of web.config of the site.

Ajax,Master page problem in Sharepoint 2007 [MOSS]

Problem:
Ajax is not working as expected in SharePoint 2007.

Solution:
1. First we need to install Ajax extensions on the SharePoint server.
2. After installed Ajax, We need to add the corresponding entries in web.config file to know the web application that the script manage, ajax requests etc... For this we need to change the configuration.
3. Copy all the ajax dlls to GAC and then follow the instructions below.

There are plenty of problems while integrating Ajax into SharePoint when i was very new to SharePoint. I solved those problems after a long research on Masterpage and Java scrpt.

Here are the steps i followed.
Before change any of the file as mentioned below please take the backup of every file and save it in some safe location.

When i was new to learn SharePoint, i implemented this. I am not completly sure that we need to change the authorizedTypes Tag in web.config of my site ot not, but it works.
The changed section looks like below.

Web.Config changes

<authorizedTypes>
<authorizedType Assembly="System.Workflow.Activities, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Workflow.*" TypeName="*" Authorized="True" />
<authorizedType Assembly="System.Workflow.ComponentModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Workflow.*" TypeName="*" Authorized="True" />
<authorizedType Assembly="System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Workflow.*" TypeName="*" Authorized="True" />
<authorizedType Assembly="System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System*" TypeName="*" Authorized="True" />
<authorizedType Assembly="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System*" TypeName="*" Authorized="True" />
<authorizedType Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.Workflow" TypeName="SPWorkflowActivationProperties" Authorized="True" />
<authorizedType Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.Workflow" TypeName="SPWorkflowTaskProperties" Authorized="True" />
<authorizedType Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.Workflow" TypeName="SPWorkflowHistoryEventType" Authorized="True" />
<authorizedType Assembly="Microsoft.SharePoint.WorkflowActions, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.WorkflowActions" TypeName="*" Authorized="True" />
<authorizedType Assembly="System.Workflow.Activities, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Workflow.*" TypeName="*" Authorized="True" />
<authorizedType Assembly="System.Workflow.ComponentModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Workflow.*" TypeName="*" Authorized="True" />
<authorizedType Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.Workflow" TypeName="SPWorkflowActivationProperties" Authorized="True" />
<authorizedType Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.Workflow" TypeName="SPWorkflowTaskProperties" Authorized="True" />
<authorizedType Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.Workflow" TypeName="SPWorkflowHistoryEventType" Authorized="True" />
<authorizedType Assembly="Microsoft.SharePoint.WorkflowActions, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.WorkflowActions" TypeName="*" Authorized="True" />
<authorizedType Assembly="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System" TypeName="Guid" Authorized="True" />
<authorizedType Assembly="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System" TypeName="DateTime" Authorized="True" />
<authorizedType Assembly="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System" TypeName="Boolean" Authorized="True" />
<authorizedType Assembly="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System" TypeName="Double" Authorized="True" />
<authorizedType Assembly="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System" TypeName="String" Authorized="True" />
<authorizedType Assembly="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System.Collections" TypeName="Hashtable" Authorized="True" />
<authorizedType Assembly="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System.Collections" TypeName="ArrayList" Authorized="True" />
<authorizedType Assembly="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System.Diagnostics" TypeName="DebuggableAttribute" Authorized="True" />
<authorizedType Assembly="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System.Runtime.CompilerServices" TypeName="CompilationRelaxationsAttribute" Authorized="True" />
<authorizedType Assembly="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System.Runtime.CompilerServices" TypeName="RuntimeCompatibilityAttribute" Authorized="True" />
<authorizedType Assembly="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System" TypeName="Int32" Authorized="True" />
<authorizedType Assembly="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System" TypeName="TimeSpan" Authorized="True" />
<authorizedType Assembly="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System.Collections.ObjectModel" TypeName="Collection`1" Authorized="True" />
</authorizedTypes>

Master page changes:
Second, i removed the onload function from BODY tag. This was causing problem, i am not sure that whether we need to remove or not!!! But it's working as expected.

I removed following section from BODY of master page.
onload="javascript:if (typeof(_spBodyOnLoadWrapper) != 'undefined') _spBodyOnLoadWrapper();"

JAVASCRIPT CHANGES:
Third, Go to init.js file in 12\TEMPLATE\LAYOUTS\1033 folder.
find the method spFormOnSubmitWrapper()
in this function, just remove the line return false; in
if (_spFormOnSubmitCalled) statement;
this is because, if that page is already posted back, sharepoint won't post it back again.
but to work AJAX calls, we need to disable it. Because Ajax sends the XmlHttpRequests many times depends on user requests, SharePoint ignore all the calls except the very first call. This is the reason when very first time you integrate Ajax into SharePoint the first call always successful and from the second call no response.
Hope it helps.

Show Desktop icon in Quick launch area in Windows server 2003.

I know most of the people are looking for it and by default we don't see the desktop icon in Windows server 2003 or XP..... So, I too faced similar problem when I was new to this IT field. It's simple and easy to implement.

Here are the steps to follow to add it to quick launch area.
  • Open notepad.
  • Copy the below code.
[Shell]
Command=2
IconFile=explorer.exe,3
[Taskbar]
Command=ToggleDesktop

  • save the file with the name ShowDesktop.scf some where on your system or on your desktop.
  • drag and drop the file to the Quick launch area.
That’s it!!! you are done. Now, you got what you need. enjoy these wonderful posts!!!
Is this helpful?

Magic of Page Load and Page Init execution

Problem:
Lack of knowledge in understanding the complete Page Life Cycle in ASP.NET.

This is very helpful in big projects. Take the below scenario.
We need to initialize an object in Master page page load event and try to access the same object in aspx page load event. But this will throw an error because aspx page load always executes first than master page page load event. Yes, it is. This is the issue by many developers as they don't understand the life cycle correct. The correct way should be, initiating the object in page init event of the master page and aspx pages.

Scenario I,
If we have a page called "Default" and a Master page called "DefaultMaster". Both have Page_Load events. When a page request comes to Default page, which Page Load event will call first?
Answer: default.aspx page load.

Scenario II,
The same pages as above with Page_Init event is also available along with Page_Load. Now which Page_Init will call first by .net run time?
Answer: Master page init event, but not default.aspx page init event.

This is the good point to know that, All page Init events will process from master page to aspx pages and all page Load events will process from aspx pages to master pages.

Page Init EventPage Load event
1. Execution sequence starts from Init event of Main master page--> Sub Master Page --> ……. -->Requested ASPX page init event.1. Execution sequence starts from Load event of Requested ASPX page --> Sub Master Page --> ……. --> Main master page load event.

Whole Page Life Cycle which contains both events should be executed as below:
Master page Init --> Sub Master Page Init --> …. --> ASPX Init --> ASPX Load--> …. --> Sub Master Page Load --> Master page Load.

How to give specific permissions to a SharePoint list item through C# to a user

SharePoint 2007 allows item level permissions. The is the big change in security trimming from SharePoint 2003. It's really very good and useful in many scenarios like when an item is belongs to others or task assigned to some other person then users can't see other's tasks or they can't edit other's tasks etc.. item level permissions are really good and useful.

Here is a small code, to set specific permissions to a user for a list item.
The below is the exaple from my SharePoint custom workflow to customize the task list.
System.Collections.Specialized.HybridDictionary taskPermissions = new System.Collections.Specialized.HybridDictionary();
taskPermissions[workflowProperties.Originator] = SPRoleType.Administrator;
taskPermissions[taskApprover] = SPRoleType.Administrator;
taskitem.SpecialPermissions = taskPermissions;

taskitem is the task list item. Hope this helps.....

How to check SMTP is working or not.

For testing SMTP server functionality, we have to follow some steps to identify that whether SMTP configured or not. Below are the steps we need to follow to check SMTP server functionality. We are using the command prompt telnet to test the server.

1. open command prompt and type :
telnet <servername> 25
Note: 25 is the port used by SMTP and <servername> is the SMTP server name.
After you hit enter you will get some output like
220 <servername> Microsoft ESMTP MAIL Service, Version: 6.0.3790.3959 ready at
Tue, 22 Jan 2008 09:10:27 -0600
It means you got response from the SMTP server and it's the clue that SMTP is setup on the server.

2. For testing response say helo to it.
Type :
helo <servername>
output:
250 <servername> Hello [IP Adress]

3. Now we need to enter the From address of the mail.
Type :
mail from: admin@domain.com
output:
250 2.1.0 admin@domain.com….Sender OK

4. It's time to enter the recepient email address.
Type : rcpt to: someID@domain.com
output:
250 2.1.5 someID@domain.com

5. Now we are left with the data of the email. i.e. subject and body.
Type : data
output:
354 Start mail input; end with <CRLF>.<CRLF>

6. Type:
subject: this is a test mail
Hi
This is test mail body
I am testing SMTP server.

7. Hit Enter, then . and then Enter.
output:
250 2.6.0 <<servername>C8wSA00000006@<servername>> Queued mail for delivery

8. Type: quit
output:
221 2.0.0 <servername> Service closing transmission channel

If you did everything as explained, you will get a mail soon.

Importance of !important property in CSS.

I think in css most of the people don't have idea or complete idea on keyword called "!important".

It will be useful in many scenarios where we have plenty of style sheets and want to overwrite all the styles applied to an element with some other styles. We know that applying styles in HTML for controls hierarchy will be like this, Which styles are very close to the element those will apply finally. i.e. if we apply some styles for a division in css and if we write inline style for the same element, then always inline styles apply. That means the inline styles overwrites all other styles to that element. Like the same, in our css, if we apply different styles to an element in different places and finally if you want to overwrite the styles in a perticular section then you need to use this !important property at end of the style.

We have a scenario like where we need to overwrite all of the styles to a perticular control, there this property will help us.

Ex: .topNav

{

background-color:#990000;

}

.topNav {some other style….}

.topNav

{background-color:#818286 !important;

}

the last css declaration will overwrites all the topnav classes declared and finally it applies the background color of #818286 for top navigation.

How to know the number of days in a month in t-sql

Some times we can get requirement to know the number of days in a given month. For example, while calculating how many days remaining in a month or last day of month or any other scenarios.
Here is a small script that will give you the number of days for given month. Example purpose, i am retrieving month from the current date.

declare @numberOfDaysInMonth int;

set @numberOfDaysInMonth = DAY(DATEADD (m, 1, DATEADD (d, 1 - DAY(getdate()), getdate())) - 1);

How to know month name from month index in t-sql

When I am working with reports, this is what every time I am looking for. Everyone gives date on the report as input, and I want display the month name on the report instead of month index [1-12]. So, how to do it?

please use the below script to get the name of the month by month index.
DateName(month, convert( datetime, '2007-' + cast(month(getdate()) as varchar(2)) + '-01', 120))

Here month(getdate()) returns the current month index from getdate() function. Hope this helps...

Expand Collapse columns in a table SSRS

Problem:
How to make columns collapsible, expandable in a table Sql server reporting services.

Solution:
I asked to some people, how to do this, lot of people proposed me to use matrix. But my data is simple data and has 14 columns like first name, last name, state, city, zipcode, q1, q2, q3, h1,h2, h3 etc… I need to display the columns q1, q2, q3; h1,h2,h3 expansible and collapsible. By default when user see the report, i need to show only first name, last name, state, city, zipcode, q1, h1 columns. But the q1, h1 columns with expand, collapse symbols. When any one clicked to expand i need to show the other columns like q2,q3, and same for h2, h3.
Below is the solution what I have followed to make it work. I didn't use any matrix here, only tables.

  1. Select all the columns that you want to make expandable, collapsible.
  2. Hit F4 [Properties window] –> Select Visibility, and in that, set these values, Hidden = true and ToggleItem = ID of the textbox [Where you want to show the Expand[+], Collpse[-] symbols that text box id. in other words parent text box id.]
  3. That's it. A simple solution to the issue.