Tuesday, December 7, 2010

Download reports from Sql Server Reporting Services

I know that this is what the reporting services didn’t give us an available option. There are many scenarios we require to get the reports to the local server and edit the changes. For example, I have 10 reports and they aren’t available right now in my server or they are under source control and it is corrupted. Then only place they are available is Reporting services. From web service we can view the reports but cannot get them to the local machine. 
By using Report Manager site, we can download one report at a time but not all reports. So, I found a way which is really helpful and saves so much of time. Thanks to Gaurav, my colleague for telling me about this.
There is a free tool available for this. Which is called “Reporting Services Scripter”. This is very good tool. Which needs the report web service url and it will bring up all the reports in the window. Once you select what reports you needed and give save location, hit on script button, that’s it. It will download all selected reports to the given location.

Download it here. http://www.sqldbatips.com/showarticle.asp?ID=62
OR
http://web.archive.org/web/20120830141644/http://www.sqldbatips.com/showarticle.asp?ID=62

Remember that, before you do anything please make sure you have given the correct report web service url as shown below.
RSScriptor_Servers
From options, you will see above screen. And from Servers tab, you have to give the correct servername.
Note: The RS Scriptor is using default windows logged in credentials. So, make sure the user logged  in has access to the reports and the user role should be “Content Manager”.

Friday, November 26, 2010

Add web reference to a console application in visual studio

This is somewhat confusion to many people. We can add a service reference to console application, but when you right click on project, you didn't see a direct "Add Web Reference" option. But, there are so many requirements we have to add a web reference. So, I thought of posting it in my blog.
Solution:
  1. Create a console application using visual studio.
  2. Right click on the project and click on "Add Service Reference...".
  3. On the window, you will find the "Advanced" button at the bottom. 
  4. Click on the button and it will open service reference settings window. It has a button at bottom called "Add Web Reference".
  5. Click on it and add web reference as shown below.
That's it. We are done!!!

Thursday, November 25, 2010

Publish Nintex workflow file to all sites and libraries using code

Nintex workflows - They are easy to build workflows and customize. I used them in couple of projects and it supports many activities which we can use and build workflows according to requirements. But, this time I got a big project which has plenty of sub sites in a site collection. All sub sites are having the same site template and it has the same structure. Each sub sites has many libraries and out of them 8 are having workflow enabled.
When I got a requirement to change something in workflow then I am in trouble like how to publish the new changed workflow to all libraries. Right now I have 148 sub sites. It means I have to publish the nintex workflow to 148 * 8  = 1184 libraries. Which is not at all possible with the manual upload process. So, the only way would be writing code to publish them automatically by running it.

Few days back, I have written the post which describes the same without coding here.  But, that needs lots of prerequisites and will apply to only one site. The solution which I have written needs the updated nintex workflow file [.NWF] as input, web url and site url. It loops through all sites in the site collection and updates the each and every library with the updated nintex file successfully.

Below is the code which does that for one site:
private static void UpdateWokflowToOneSite()
{
    string siteUrl = ConfigurationManager.AppSettings["SiteUrl"];
    List<string> listNames = new List<string>() { "List - 1", "List - 2", "List - 3", "List - 4", "List - 5"};
    using (SPSite site = new SPSite(siteUrl))
    {
        string webUrl = ConfigurationManager.AppSettings["WebUrl"];

        if (string.IsNullOrEmpty(webUrl))
        {
            webUrl = "/";
        }
        using (SPWeb web = site.OpenWeb(webUrl))
        {
            byte[] rawData = File.ReadAllBytes("UpdatedNintexWorkflow.nwf");
            NintexWorkflowWS.NintexWorkflowWS ws = new NintexWorkflowWS.NintexWorkflowWS();
            ws.Url = web.Url + "/_vti_bin/NintexWorkflow/workflow.asmx";
            ws.UseDefaultCredentials = true;

            int i = 1;
            foreach (string listName in listNames)
            {
                ws.PublishFromNWF(rawData, listName, string.Format("NintexWorkflow-{0}", i), false);
                i++;
            }
        }
    }
}        

Below are the prerequisites for running above code.
  1. I have created a console application and writing code in it. So that I will get EXE as output and running it wherever needed [different servers by changing configuration file]. 
  2. We have to add the Nintex workflow web service reference to the project. So that we will call it and use it in code. The below line in the code is web service instantiation.
    NintexWorkflowWS.NintexWorkflowWS ws = new NintexWorkflowWS.NintexWorkflowWS();
    
  3.  The user who is logged in has the permissions needed to publish the nintex workflow. The administrator access are needed to run the above code.
  4. The NWF file location according to above code should be in the same location where EXE is present. By default it will be project location/bin/debug.
  5.  listNames is the variable which has all list/library names in the site to which we have to publish the workflow. In case if you want to publish to all list/libraries then replace the listNames in foreach with web.Lists.
Now, the app.config entries are configurable. Below are the configuration changes needed.
<appSettings>
    <add key="SiteUrl" value="http://sharepointsite"/>
    <add key="WebUrl" value="/"/>
  </appSettings>
    <system.serviceModel>
        <bindings />
        <client />
    </system.serviceModel>
    <applicationSettings>
        <DeployWorkflowNWF.Properties.Settings>
            <setting name="DeployWorkflowNWF_NintexWorkflowWS_NintexWorkflowWS"
                serializeAs="String">
                <value>http://sharepointsite/_vti_bin/NintexWorkflow/Workflow.asmx</value>
            </setting>
        </DeployWorkflowNWF.Properties.Settings>
    </applicationSettings>
In this, change the configuration as needed and use it.

You can use the same code loop through each and every web and publish it to all webs. I mean one more loop is enough to do that job as shown below.
private static void UpdateWokflowToAllWebs()
{
    string siteUrl = ConfigurationManager.AppSettings["SiteUrl"];
    List<string> listNames = new List<string>() { "List - 1", "List - 2", "List - 3", "List - 4", "List - 5"};
    using (SPSite site = new SPSite(siteUrl))
    {
        foreach(SPWeb web in site.AllWebs)
        {
            byte[] rawData = File.ReadAllBytes("UpdatedNintexWorkflow.nwf");
            NintexWorkflowWS.NintexWorkflowWS ws = new NintexWorkflowWS.NintexWorkflowWS();
            ws.Url = web.Url + "/_vti_bin/NintexWorkflow/workflow.asmx";
            ws.UseDefaultCredentials = true;

            int i = 1;
            foreach (string listName in listNames)
            {
                ws.PublishFromNWF(rawData, listName, string.Format("NintexWorkflow-{0}", i), false);
                i++;
            }
        }
    }
}

There we are done. Just run the EXE and it will update the workflow to each and every library in a web.

Complete project is available for download here. Please let me know, if you need any more help.

Friday, November 5, 2010

STSADM - Object reference not set to instance of an object

I know this is the error which developers see most of the times. This is very basic error and it raises when we tried to access NULL reference object. But, What is if it comes while accessing STSADM? In SharePoint everyone knows the role of STSADM and the advantage of it. If you try to do some operation using STSADM tool and ends with the error "Object reference not set to instance of an object" then it is very difficult to trace as it is not giving us the enough information. But, with the experience, we get some ideas and solutions. Most of us know the resolution but I want to place everything what I know to my readers on this blog.

Resolution:
The user who runs the STSADM on the server should have access to the SharePoint Admin content database. If he don't have access, but he is administrator on server, has full access to central administration and farm administrator access then still no use. He should have access to the admin content database. Because whatever we do using STSADM then it is indirectly dealing with database only. So, user logged in should have access to database.

This is one of the main thing which we need to remember in administration side. Hope you liked it and you remember it forever. And mainly this scenario will come on environment where the farm server setup and database server is different from SharePoint server.

Operation is not valid due to the current state of the object when making changes to SPListItem object using elevated previliges

This is known error to sharepoint developers that when try to update/delete a SharePoint list item using system account. Means using SPSecurity.RunWithElevatedPrivileges() method. I am not sure, why it is not allowing to update or delete a file in this code block. But, there is work around for it. You can still edit the item using elevated privileges. Here is a wonderful post, which helped me great and all credits to him.
Make changes to SPListItem using elevated privileges
I am really surprised by seeing the code in his article. It is completely unexpected and it is working great. I am really not believed when I saw the code very first time, but it is working.

But, make sure you are disposing the objects correct. Hope this will help you too to fix the problem "Operation is not valid due to the current state of the object".

Table of contents web part remove max 50 limit

We use the "Table of contents" web part on SharePoint landing pages to give access to users to easily navigate to the sites/pages. But, there is a default limitation on the display items in left navigation or table of web part contents  in sharepoint. By default it shows only 50. If you have more than 50 items [either  sub sites or pages] in a site then it will not show up. To increase the limit or to remove limit, please do below changes.
  1. Go to the web.config of the SharePoint site through file system. Usually, it is located at "C:\inetpub\wwwroot\wss\virtualdirectories\port number".
  2.  Please take the back up of the web.config file before do any changes.
  3. Find the below tags in the web.config file.
    <add name="GlobalNavSiteMapProvider" description="CMS provider for Global navigation" type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=13.0.0.0, Culture=neutral, PublicKeyToken=94de0004b6e3fcc5" NavigationType="Global" EncodeOutput="true" />
    <add name="CombinedNavSiteMapProvider" description="CMS provider for Combined navigation" type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=13.0.0.0, Culture=neutral, PublicKeyToken=94de0004b6e3fcc5" NavigationType="Combined" EncodeOutput="true" />
    <add name="CurrentNavSiteMapProvider" description="CMS provider for Current navigation" type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=13.0.0.0, Culture=neutral, PublicKeyToken=94de0004b6e3fcc5" NavigationType="Current" EncodeOutput="true" />
    <add name="CurrentNavSiteMapProviderNoEncode" description="CMS provider for Current navigation, no encoding of output" type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=13.0.0.0, Culture=neutral, PublicKeyToken=94de0004b6e3fcc5" NavigationType="Current" EncodeOutput="false" />
    
  4. All the above tags are belongs to the navigation providers. They are the sources for the navigation controls. We can add any attributes which it recognizes to control the navigation.
  5. Now, according to our problem, we have to add an attribute which can control the number of items to display in navigation. The attribute is, "DynamicChildLimit".  Which accepts integer value. You can give any value in there to control navigation items. For example, if you give 20, then it will show you the top 20 items sorted by created. If you give 0, then it means no limit. Display how many items it has. 
  6. So, we have to add the attribute to all the above tags, so that it should looks like below.
    <add name="GlobalNavSiteMapProvider" description="CMS provider for Global navigation" type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=13.0.0.0, Culture=neutral, PublicKeyToken=94de0004b6e3fcc5" NavigationType="Global" EncodeOutput="true" DynamicChildLimit="0" />
    <add name="CombinedNavSiteMapProvider" description="CMS provider for Combined navigation" type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=13.0.0.0, Culture=neutral, PublicKeyToken=94de0004b6e3fcc5" NavigationType="Combined" EncodeOutput="true" DynamicChildLimit="0" />
    <add name="CurrentNavSiteMapProvider" description="CMS provider for Current navigation" type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=13.0.0.0, Culture=neutral, PublicKeyToken=94de0004b6e3fcc5" NavigationType="Current" EncodeOutput="true" DynamicChildLimit="0" />
    <add name="CurrentNavSiteMapProviderNoEncode" description="CMS provider for Current navigation, no encoding of output" type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=13.0.0.0, Culture=neutral, PublicKeyToken=94de0004b6e3fcc5" NavigationType="Current" EncodeOutput="false" DynamicChildLimit="0" />
    
Note: For removing the limit, I have used 0 in the above example. Please use the number according to your requirements.

Once you have changed the web.config file, save it and check the site. It should display the navigation items according to the setting you have given. Hope it helped.

Sunday, October 17, 2010

SharePoint 2007 Limitations complete list

There are so many posts in the Internet describes about this. But, there is no place where I found all at once. So, I am planning to keep this post up to date with whatever I find. If I miss anything then please add here or let me know. That will be a great help.
  1. SharePoint maximum limitations 
  2. Performance limits 
  3. Scaling limits 
I think, the above three posts covers most of them. But, below are some of the things which we need to consider as well.
  1. Unsupported characters: These characters are not allowed in SharePoint or WSS /\:*?"<>|#{}%&~ or tab characters and multiple periods.
  2. File or folder names with Trailing spaces: File or folder names in SharePoint or WSS won't support any trailing spaces.
  3. File and folder names length: File or folder names longer than 255 characters will not be allowed.
  4. Number of columns limitation in a list:
  • 64 text fields, including the following field types: Single line of text, Choice, Hyperlink, or Picture.
  • 16 Lookup fields
  • 16 Date and Time fields
  • 16 Yes/No fields
  • 32 Number and Currency fields
  • 32 Multiple lines of text fields 

I believe these are enough for a SharePoint architect to get good idea on limitations of SharePoint. Hope these helps and please update me if you find any.

Template Explorer in SQL Server 2008

I know, most of us do not know what it is... But, there are nice advantages of it and everyone should know about it. Template Explorer contains so many templates which helps us to understand many things and these templates have many examples on how we can write or do things through SQL queries. There are lot of default templates available like Backup, Restore, Database Mail, Trigger, user, login etc...

To view the Template Explorer, follow the steps below.
  1. Open Sql Server.
  2. From "View" menu, select "Template Explorer".
This opens up the template explorer and there are lot of folders which helps you to understand and do some magic. To give the template parameters, no need to go to the sql code and edit. You can directly change them in the editor as described below.
  1. Open some template.
  2. Now, click on Query menu and select "Specify Values for Template Parameters".
  3. It will show you a windows with all parameters the template is looking for for the selected template.
That's it!!! This helped me to understand many things. Hope this helps to you too..

Find table size used in SQL Server

In a database, when size is growing then we have to find which table is taking more size. Then we have to query database to find what is the table taking maximum size. Log is also one of the factor which causes the database size grow in very huge amount. But, except logs, if you want to find the table which takes max size is, then use below command.

Command:
EXEC sp_spaceused 'Student'

Output:
namerowsreserveddataindex_sizeunused
Student918464 KB256 KB152 KB56 KB

So, using the system stored procedure "SP_SpaceUsed", we will find the table size used. The only input parameter the SPROC expects is table name.
Hope you enjoyed this post.

Find the database size in SQL Server

This is very important to find regularly if you are hosting the web site in hosting providers. The database size grows day to day and we have to find it more often. otherwise it grows than the given size and account will be suspended.  Below is the command used to find the size of the database and logs.

SELECT name,size from sys.database_files

Here is the sample output:
NameSize
SampleDatabase384
SampleDatabase_log392


Hope this helps.

List all Tables using SQL Query in a database

This is not needed in general development times. But, very rare cases only we have to get these kind of requirements and use these rarely used commands. I have a requirement where I need to know the list of tables in a database and do something. So, below is the simple query which is used to list or display the tables in a database.

select [name] from dbo.sysobjects where OBJECTPROPERTY(id, N'IsUserTable') = 1

"sysobjects" is the system table which holds all objects in a database. By using where clause "IsUserTable" returns true if it is a table and filtering the results.
Hope this helps.

Sql Server Management Studio for Sql Azure

Sql Azure is very powerful and good to know these concepts. I love it and very nice technology these days. Windows Azure is going to be very powerful in near future. When you install the Sql Azure in the system, then you may need to search for downloading the SSMS for it. Here are the links for it.

SSMS for Sql Azure 32-bit
SSMS for Sql Azure 64-bit

Thursday, September 30, 2010

Update the Nintex workflow to multiple lists and libraries in a SharePoint site

Special thanks to Vadim Tabakman.
 It is a special requirement. Nintex workflows are very  helpful in some scenarios to achieve things in simple and easy way. I got a requirement that I have to implement a workflow which needs to be used in many document libraries and list. As we know the SharePoint limitation, we can not apply the workflow for the content type. So, the only way we can do is adding workflow to each and every library needed. This is difficult, but I believe this is the only way we have to proceed. The big problem here is, when we have the requirement to change the workflow according to new changes then the problem starts. We have to change it in each and every library or list where workflow is deployed. This is very difficult in real time. So, we need some other way which we have to do automation. I am googling for the solution and luckily I found a wonderful solution here.

I will explain you very detail what "Vadim Tabakman" solution is.
He has created a document library and custom list which are used to add or update the custom nintex workflow in all libraries and lists.

Tuesday, September 28, 2010

Replace single quote with two quotes in XSLT

I know most of the people will not need it as very rare this requirement comes and because of it we have to waste hours and hours. In net there are plenty of articles, posts says about how to do replace in XSLT. But, most of them has some requirements like the replace() built in method needs XSLT 2.0 version, or some thing something.... But, if you need simple replace method regardless of the version you have, then you are at right place. There are lot of custom functions written on this already. But, no one of them works for the requirement I have. That is replacing the single quote with two quotes in XSLT. 

The main requirement here is, I am more of SharePoint guy, I use infopath forms for collecting data from users and save them to backend[database]. In the process of it, I have comments fields in the form. There are chances that user may enter single quotes['] in their comments. But, while saving them to the database, the single quote ['] giving problems. Everyone knows that this is the basic problem. So, I have to replace single quote with two single quotes so that the problem will go away.

Saturday, September 25, 2010

This session has exceeded the amount of allowable resources - Infopath form error

If you are working with infopath forms and your form is really big [I mean, having lot of controls and with so many actions] then you should get this error at some point. Most of the developers did not get it as it will come very rarely.

Error details:
"This session has exceeded the amount of allowable resources."

Event Viewer details:

Event Type:      Error
Event Source:    Office SharePoint Server
Event Category:  Forms Services Runtime
Event ID:        5737
Description:     
Number of form actions 208, has exceeded 200, the maximum allowable value 
per request. This value is configurable and can be changed by the administrator.
So, when we see the log description, it is saying that the form actions is beyond the SharePoint default form actions allowed. SharePoint by default allows 200 form actions per postback of a form. But, here the form I have used is using more than 200. My case it is 208. So, it will not allow to save or submit the form and throw the above error.

GridView and export to excel

This is very simple to implement in ASP.NET. But, there are possibilities to get problems in exporting to excel from grid view. When you bind data to gridview and write some logic to export to excel then it will not be enough. We have to check or write some additional logic which will help us to solve the problems. Below is the explanation for all problems we may get in the complete process along with detailed solution.

You may encounter below errors when you try to implement the export to excel for gridview.
1. Control of type "GridView" must be placed inside of the form tag with runat="server"
This is very well known error to ASP.NET developers and by seeing it, we think that the control is not inside the form with runat server. But this is not correct. This error will come even if we put the GridView inside form with runat server. The reason is, in the export to excel logic we are calling RenderControl() method of GridView. So, to render it without any issues we have to override the "VerifyRenderingInServerForm" in our code.  Below is the syntax of the event. Add this to the c# code in code behind file. Remember this event is a Page event means this method you should place in ASPX page. If you are using user control to implement this export to excel logic then below are the ways to go.
1. If your user control is using by less than 3-4 pages then go to each and every page and add this event to the page.
2. If your user control is using by more than 5 pages then the best solution is to create a base page [Which inherits from System.Web.UI.Page class] and all your ASPX pages should inherit from this base page.

public override void VerifyRenderingInServerForm(Control control)
{
    //Confirms that an HtmlForm control is rendered for the specified ASP.NET 
    //server control at run time.
}
Now, after we added the event to page, the error will go away for sure.

Saturday, September 11, 2010

The assembly from form template conflicts with a same named assembly in form template

This is the exception which was coming when I tried to deploy the infopath forms to SharePoint environment.

This is the background of the problem. I have infopath project created in visual studio and infopath has 3 views. According to my requirement I have to publish each view as a single infopath form. So totally 3 infopath forms as output. The infopath form has form code in c#. So, we have to deploy dll as well. But, as one version of infopath is already in production, I have to move the new version to production. But, according to some dependency problems, I have to keep the dll of the infopath project as same version as production. So, what I did was opening the AssemblyInfo.cs and changed the assembly version to hard coded like 1.0.3098.12321. There it started the problem. When I tried to deploy the infopath forms below is the exception it was coming.

The assembly infopathproject.dll from form template someform.xsn conflicts with a same named assembly in form template another.xsn

So, after research around 1-2 hours, I found that the three xsn forms are pointing the same dll [I mean along with version]. So, infopath forms are having same dll reference and leads the conflict.

The resolution for this problem is, reverting back the assembly information back to 1.0.* solved the problem. Now infopath forms are pointing to same dll but with different versions. So, problem resolved.

So, if you have the same requirement like same dll using for different infopath forms then, please don't forget to make auto generate versioning for the assembly like 1.0.*.

Hope this helps to solve the problem.

Thursday, September 9, 2010

Setting views dynamically in infopath form through code

When working with infopath forms, there are lot of things we have to know. This is not very easy to implement, publish and using it. So, we have to know complete details about infopath in all aspects. I had a requirement in infopath, while loading depends on some scenario I have to switch the view. While form is loading I have logic written to know what view I have to set. But, once I got the view name from logic, how to set that to infopath form? Below is the simple code which works for that requirement.
e.SetDefaultView("PBB"); 
the "e" used in this code is the LoadingEventArgs object in the form event. It has the method named SetDefaultView(), Which takes the view name as the parameter. So, once you set it, it will apply the view to the infopath and display the view on the form.

Hope this helps to understand better the infopath and code.

Thursday, August 26, 2010

Infopath form cannot save the following form - Form is Read Only

I have created the infopath project in Visual Studio and deploying into SharePoint environment. After some days, I got to change the infopath form to match the new requirement and redeploy to the SharePoint environment. I have opened the Visual Studio and spent half an hour to edit all the changes and tried to save the form. But, while saving it was started giving me the alert message that "The infopath form cannot save the following form: Template Name is ready only." I did not understand and check all file properties of the manifest.xsf and unchecked the checkbox read only. Still it was giving me the same error message. The error message was completely confused me and no any other clue. So, started searching in internet for the solution and after searched about an hour, found the information. If you have opened the infopath form, then close it. [No other way, you will lose all changes you have made.]

Resolution:
  1. Open the manifest.xsf in notepad.
  2. PublishUrl: Search for "publishurl". I believe, this pointed to the old location other than what actual the form is submitted to. Make it empty [No problem].
  3. runtimeCompatibilityURL: in the notepad, search again for "runtimeCompatibilityURL". Now change its value to "http://sharepointserver/_vti_bin/FormsServices.asmx". 
  4. If you are using the source control like VSS, Source vault, TFS or whatever then you have to do below things.
  • Open Visual Studio and checkout all the files in the Infopath Form Template folder.
  • Once all checked out, then close the Visual Studio and reopen.
    Note: replace sharepointserver in above url with your sharepoint server name.

    Check for more information here. MSDN
    That's it. Now, you have to reopen the file and do whatever changes you have to do. Enjoy.

    Monday, August 23, 2010

    How to get the files from GAC in Windows

    This is what I think about since I started working on Windows. I don't know how to see the Windows GAC files and get them for other use. For example, sometimes I deploy the files to GAC location and then want to move the same dll to some other server. But, as usual, the original files missed from the file system. The only location I can get them is GAC. But, don't know how to get the files from GAC. This is a big question and resolved my my colleague Phani recently. I was surprised and felt very happy after the resolution he found and now I am utilizing it very efficiently.
    There is a command available in Windows for doing the task. "subst".

    The command will create a virtual folder of all GAC files to a separate drive. Below is the syntax:
    subst Z: C:\windows\Assembly
    
    When you go to the my computer you will find a new drive under the regular drives. Just go inside and you can see all the GAC files. The folder GAC_MSIL is what your all files reside in. Copy the dll's you needed and paste them in some safe location for backup.

    To remove the Z drive from machine, then use below command.
    subst Z: /D
    
    All credits goes to Phani and take a look at this post from him for more information. Enjoy some nice tips and rare findings from the blog.

    Check drop down list contains a value in c#

    This is again a very simple post and want to share. I have seen many people write good coding, but, sometimes they don't pick efficient way to do somethings. When we do code reviews we can identify some code parts are very simple to implement but they implement it in complex way, want to correct them. A simple scenario is, how to check a drop down contains a value. Some people are looping through all items and finding the item exists or not. Some people are doing some complex logic etc. But, below is what I believe the good and simple way of finding a value is in drop down list of items.
    if (ddlUserType.Items.FindByValue("someValue") != null)  
    {  
       ddlUserType.SelectedValue = "someValue";  
    } 
    
    Do you think, is there any efficient way of doing this?

    bind Enum to drop down list in ASP.NET

    This the question asked by so many people around me and I also faced issues couple of times of my early stages of learning.This is simple but, how to get value and names as a collection and bind to drop down list is a bit difficult. Below is the simple logic to read all enums and create a list item and bind to drop down list. [There are many ways to get this done, but I believe below is the best way.]
    foreach (UserType ut in Enum.GetValues(typeof(UserType)))
    {
    ListItem item = new ListItem(Enum.GetName(typeof(UserType), ut), ((int)ut).ToString("D"));
    ddlUserType.Items.Add(item);
    }
    
    I think, you like this post. Let me know if you have any issues.

    Friday, August 20, 2010

    Know the site template used for the SharePoint site

    Hello all, Hope all are doing fine. I believe this is very rarely needed post that we need to know what site template [Publishing site, workspace, meeting workspace, team portal etc..] was used for a particular SharePoint site. From the UI [means by navigating to SharePoint site through browser] we can't identify this. So, we need to follow either of the steps given below to identify the template used for a specific site.
    1. First option is, this is my recommended choice and very easy too. By using SharePoint Manager tool [available for both 2010 and 2007.] Download it for free from Codeplex and install it. Now, open the SharePoint Manager and connect to the SharePoint site collection. When you click on a specific SharePoint site, on the right side it will show you all the properties available in the SP object model for that site. In it find for TemplateID and check the value showing there. That's it. What is TemplateID and how to know template name from it? Navigate to end of this post for TemplateID to Name mapping.

    Monday, August 16, 2010

    Check string contains numbers in T-SQL

    I know this is looking very simple when we read. But, I had a requirement where I need to filter strings from string data type column in T-SQL. Means, some strings in database having numbers in them, and I need to get them out and do some processing. When I started implementing this, I had so many ideas and thought like, looping through all characters in each string and check whether it has numbers in it or not. But, this is not efficient and may be a stupid implementation. And after thought about it sometime, started reading T-SQL documentation and found a wonderful function which is already built in in T-sql. I am saved. Very happy to see that function and that is working very great.

    Tuesday, August 10, 2010

    Visual Studio intellisense for HTML 5

    It's the time to use the new technologies like HTML 5. Everyone of us knew about what this is and how easy now to generate some nice and rich UI without put much efforts. No complex javascript, no silverlight or flash is required most of the time and many more advantages. There are plenty of changes in CSS too. So, I believe we should start using HTML 5 in our applications. Because almost all browsers are supporting it.
    After I have written some posts on Visual Studio intellisense on Jquery and SharePoint 2010 ECMAscript Client OM, I want to write similar on the intellisense for HTML 5.

    This is very simple process than any other we have followed.

    Wednesday, July 21, 2010

    The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)

     IIS Manager Error: The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)

    The above is the exception comes most of the times when you are using the default web site in windows 7. Automatically it will stop the site and when we try to start then the above exception is coming. Because of it, no web sites, applications are running and unable to proceed to any further step. I know that the default web site uses the port number 80 by default. For testing purposes I have changed the port number to 9999 and tried to start the default web site and surprisingly it started and everything running fine. So, I fixed to the problem that the issue is only because of the port 80. I came to conclusion that someone else other than IIS web site is using the port 80.

    Now, we found the problem. We need to look for solution. But, how to know who are using the port 80 other than IIS?

     Here is the post on it. "How to find what process is using which port?". The helped me a lot to find out the problem in minutes.

    How to know what process is using which port in windows

    I believe this is going to be a very helpful post to most of the readers. So many times I need to know about this. This is a great tip to resolve so many problems. So, it is one of my hot tips for identifying the problems.

    We usually install third party software like Skype, TeamViewer etc. in the windows OS, then they will default take some port numbers available. Then there are chances they will create some problem as explained below. [This is why we need to take care of installing software on the servers or production machines. We should install if and only if we really need them. :)] Below is the complete scenario.

    Friday, July 16, 2010

    More SharePoint 2010 templates in Visual Studio 2010

    I am working on SharePoint 2010 these days and all the development is on Visual Studio 2010. The IDE is very cool and great features. Really very helpful for developers and administrators as everything is builtin like deploy, configure and easy development. I really love it. There are plenty of SharePoint 2010 templates are available by default in Visual Studio. Here are some from Microsoft with extra templates. Install them and use them for time saving and learn more...
    http://code.msdn.microsoft.com/vsixforsp

    Detect request is from iPad in ASP.NET

    iPad. People slowly liking it. Few days ago, I have written a post on how to detect the request is from the iPhone. So, as iPad applications are also growing day to day, I want to give you a small tip on how to detect requests are from iPad. So that you will write logic which is specific to the iPad like html, CSS, scripts etc.

    Detect request from iPad in ASP.NET [C#]:
    if(HttpContext.Current.Request.UserAgent.ToLower().Contains("ipad"))
    {
         //iPad is the requested client. Write logic here which is specific to iPad.
    }
    else
    {
         //Normal browsers [from computers] requested.
    }

    Detect the iPad request in Java script:
    if (navigator.userAgent.match(/iPad/i)

    Very simple, isn't it. Hope this helps.

    Saturday, June 26, 2010

    Open all anchor links in new window

    I believe this post is going to be very interesting to many people who read this post. Because the first question is what is the need to open links in new window? Is it a big deal to open links in new window? What are the advantages? Why we need to implement this in our sites or blogs?

    Take my blog for example.  I have write big posts some times and place more links. I want the user to see the links to be opened in new windows as they are still reading my pages. If the link opened in the same page, then it will be a problem to go and come back and start reading from the position they were. That won't give good experience. I want them to be stayed on my blog page and open all the links in new window. So that user is always on my blog page and if they wants then they can move across pages. It's not bad at all.

    How many ways are there to implement this?
    1. Make all links in web page open in new window.
    2. Only some part of the web page links will be opened in new window.

    Thursday, June 24, 2010

    ULS Viewer - SharePoint Log Viewer - A nice SharePoint Tool

    In SharePoint, I know the big pain in development is if we get any exceptions or errors in the code we have implemented, then go back to log files and scroll or search to the exception or error details and try to solve it. The notepad file size could be in MB's. It's difficult to maintain and see what was caused the problem very easily. Most of times it frustrates to search and find the corresponding problem as notepad is very slow if log file size is huge. I am always think like, is there any better way to see and find the details without struggling a lot. One way I found was my previous post "How to see actual exception and errors directly on SharePoint web page". But, that won't help always to find the problem.

    That is the reason I started to find a good solution for it. Luckily Microsoft understand this and developed a nice tool for us. That is called ULS Viewer. This is the windows application which takes the ULS log file as input and loads the log files very faster than notepad and shows us as grid of columns. You can do plenty of customization to it by sorting, filtering, searching, highlighting etc... You can find the problems in your code in very less time. I find this is one of great and superb tools every SharePoint developer should use. It surely decrease the analysis time on finding exception or error details.

    For more details about the ULS Viewer: http://code.msdn.microsoft.com/ULSViewer
    For free download: http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=ULSViewer&DownloadId=7482

    For complete documentation: http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=ULSViewer&DownloadId=7483

    So, use it and make your life more comfortable. Subscribe to all my posts and stay with me. I always try to share and help the devs to make development faster with the already existing tools. But, the things is we need to know about them, I will do that part for you. Happy SharePoint development.

    Wednesday, June 23, 2010

    SharePoint 2010 ECMAScript Intellisense in Visual Studio 2010

    This post is a very big help to the SharePoint 2010 developers. We need the intellisense help to write code fast in our SharePoint applications. But, in SP2010 BETA I faced so many problems to find what methods a java script object has. After written a long post on how to get the java script intellisense working in Visual Studio 2008 this is now an easy for me to do the same on Visual Studio 2010. I just tried the same implementation in VS 2010 and that worked great. So, there I started and started using it in ECMAScript development. When I first see the intellisense working in VS 2010 felt very very happy and jumped into the air. Because, before to find the same methods in the ECMAScript object, I had wasted hours and hours. One of the example is this post "How to know all methods in SP object".

    Solution:
    By using reference tag everything possible.

    Tuesday, June 22, 2010

    detect request is from iPhone in ASP.NET

    The usage of mobiles is growing and growing day to day and most of the users are browsing from their mobiles and do the stuff. So, it is becoming important to support the mobile phones the web sites we are developing. Recently we have developed applications which support for iPhone and I am strongly believing that ASP.NET MVC is the best architecture in all ASP.NET versions.

    As we are developing applications it can be accessible from any where and any device including computers, mobiles, iphone, ipod or whatever. But, the important thing is UI. A web site how it looks like on computers is completely different from the mobile. So, we need to detect the user agent or the client who requested the site. So, if  request from computer browsers then we don't need to anything as this is the default type. Whereas the request from the mobile phones then we need to render different UI. So, this post will explains that.

    Detect request from iPhone in ASP.NET [C#]:
    if(HttpContext.Current.Request.UserAgent.ToLower.Contains("iphone"))
    {
         //iPhone is the requested client. Write logic here.
    }
    else
    {
         //Normal browsers [from computers] requested.
    }

    Detect the iPhone request in Java script:
    if (navigator.userAgent.match(/iPhone/i)
    So, depends on the client we will write the corresponding logic in the specific block to switch UI. Hope this helps.

    Thursday, June 17, 2010

    Read More link to blogger posts without HTML changes

    This is really a very helpful post I believe. Most of the times I write long posts and explain each and every part in the solution I found. So, I really need to show only specific length of each post and add a link called Read More at the end of the post on the blog home page. So, that users get chance to see more posts and look more posts. And the loading of the main page will be faster as the content is less. So, there are lot of advantages by placing the read more link on the home page for each post.

    I have tried so many solutions and didn't impress by any of them. Some of them are disturbing my HTML as after specific characters add the read more link. Another option is, strip the HTML from the post and add the read more link after specific characters, but that also removes the blog styles for P tag, div Tag or any other custom styles we have applied. Sp, to get this working either we need to change the Blog HTML or add bunch of Javascript code to do that. This is not very easy to maintain and useful. So, what to do, can't I do it? So, after a very long research and read so much I want to give better user experience to my users to read what they want on my blog. Finally came up with a nice and simple solution which do not need much HTML changes or customization.

    Friday, June 4, 2010

    Best Split UDF function with delimeter in T-SQL to return result as a table

    This is what the function I am using since many years to get the table of values in the given ID's which are separated by some delimiter.

    Simple to understand and see the example in the comments in below function.
    From the UI there are sometimes need of sending the data or ID's in the string format separated by a delimiter. So, in database, we need to grab them and apply some operations like with the ID's we need to get the records from a table. In this case, we need to use this UDF function. Everyone knows that inner joins are far better than IN clause or something else. So, what the approach I have taken here is, I will get the delimited string and delimiter and pass them to UDF function. It returns me a table which has the rows consists of the ID's. By using this table, I will apply whatever operation I want and get the result.

    Know COUNT of bit column using Group by in T-SQL

    Here is a scenario most of the times we use and look for. I have a bit column in database table and want to filter the count of true count and false count by applying Group By on it. For example, below is the simple scenario I came up with to better present you.

    We are storing employee details in database and taking attendance once in every day. So, in reporting, I want to see month wise report on how many are total, absent and present. Now, the challenge is need to find out how many are total employee and among them how many are attended and how many are absent in the given month and year.

    Compare Date only in Datetime field in T-SQL

    This is simple still I want to share as this is asked by so many people around. So, here is the scenario why it's needed. [Mainly in reporting.]

    From the UI, users selects the date and by using that date we need to compare the datetime field in database and produce some result. But, in database it actually the datetime field, we can't apply equal operator on it as it fails to do it because of time part.

    I know, now there is a need of time for thinking on how to do it.

    Group By Date Time without milliseconds in T-SQL

    There are lot of requirements which needs some complex logic and put maximum effort to implement them. The below scenario is the one I want to explain in writing T-SQL queries.

    The requirement is very simple, I want to apply group by on DateTime field in database which does not includes the milliseconds part from the time. So, on the UI I need to group by and show records with seconds and but not with milliseconds.

    In my first try, I just wrote the T-SQL query by directly applying the GROUP BY clause on the DateTime field and found that milliseconds are also including. Which is not matching with what exactly I was looking for. So, tested lot of scenarios and nothing works. I am out of ideas on how to trim the milliseconds and apply group by.

    Tuesday, May 4, 2010

    Developer Dashboard in SharePoint 2010

    What is developer dashboard:
    SharePoint is very big system and consists of so many modules integrated. We can do lot of customization and all our code will be deployed to SharePoint and end users will use it. But, what if client comes to you with the question, "why my SharePoint site is loading very slow?" How you proceed?
    First thing you need to check is all server configurations like is memory is sufficient/ Processor is sufficient etc.. After you found they are more than enough, now it's time to find problem in the code. Till SharePoint 2007, it's very difficult to find which part of the code is taking how much time and analyze it better. But luckily in SharePoint 2010, Microsoft added a very nice feature for developers to detect which module is taking how much time. It will record all the requests and the time to get response etc.... This is what we are calling Developer Dashboard.

    The great advantatge with it is, it will differ the requests and show like, database queries [Which query took how much time], SPRequest allocation, Webpart event offsets, etc in very detailed way. I really love it. Thanks a ton to SharePoint 2010 team.

    Process Explorer Free download

    Every time, I have needed to know what file, folder, process is opened and running. And sometimes which dll is loaded and running etc.....
    The existing windows task manager won't give me all the information I needed. So, I found it's a great tool for my problem and want to share with all of my readers. Get this free download.
    Process explorer download for FREE

    Free SharePoint 2010 Developer tutorial

    This is the excellent developer guide which really has plenty of things to understand well. I strongly recommend this to you. So, please get it and start reading it for better understanding and knowledge on SharePoint 2010. Get yourself strong in the skills. Easy to learn.
    Download SharePoint Developer Guide free

    UserProfileServiceUserStatisticsWebPart:LoadControl failed - SharePoint 2010 Exception

    Today, when I installed the SharePoint 2010 server, First task I want to complete is user profile import. Everyone knows that there was a big bug in the BETA version in this module. So, I went there in manage services screen and clicked the "User Profile Synchronization Service". Surprisingly I got the error screen and don't know what to do. That is unspecified error screen and not given any error details.
    But, we have an excellent resource to solve all these issues. I mean SharePoint Log files. When I went there and looked into the file, I found below exception message.

    Monday, May 3, 2010

    Download SharePoint 2010 server, foundation, office 2010

    Hello all,
    After waited so many days finally the RTM versions are released and below are the details.

    SharePoint foundation server (2010)
    SharePoint designer 2010

    Note: the below downloads are for subscribers and premier users only.
    SharePoint server 2010
    Office professional plus 2010 [64-bit]
    Office professional plus 2010 [32-bit]

    Download SharePoint designer 2010 for free

    I believe you have read my previous posts on SharePoint designer 2010. And now complete release available on Microsoft Downloads center.

    64-bit

    32-bit

    Saturday, May 1, 2010

    Silverlight Client Object Model - Samples and Examples in SharePoint 2010

    This is the post which belongs to the same series of the samples and examples of the Client Object Model in SharePoint 2010. So, this post I give you a start up examples for Silverlight Client OM.

    Download the examples from here.
    Download Silverlight Client OM examples and samples.

    Let me know the feedback and if you need anything else.

    Friday, April 23, 2010

    SharePoint 2010 ECMAScript Client Object Model - Samples and Examples

    I have done sufficient experiments on SharePoint 2010 Client Object Model and other features while I am learning SharePoint 2010. Now, my work is to share the knowledge I have gained. So, part of that is all these examples and samples. I hope they will help you to better understand and keep you up to date with new technologies.

    As we know SharePoint 2010 provides the nice API for 3 client object models, in this post I have concentrated on ECMAScript client object model.

    Download the code from here and start see the code and try to learn it. All these examples are my own development and not copied from any where in the internet.
    Download ECMAScript Client Object Model Samples and Examples.

    Before take a look at the code, you should read the article for where to place the code and how to use.
    ECMAScript - Complete details

    Tuesday, April 13, 2010

    SharePoint 2010 Managed Client Object Model - Samples and Examples

    After spent good amount of time on learning and experimenting on SharePoint 2010 client object model, I want give some examples and samples to my users. In that plan, here are some examples which helps you to understand and make better coding.

    In this post I am concentrating on Managed Client Object Model and examples.
    Please find the zip file here and download and start see coding and understand it. It has all the C# projects in a solution which are simple to understand and write.
    Download Managed Client Object Model Samples and Examples.

    All these examples are created by me to give some practice to learn SharePoint programming to my users. So, if you find it useful then please share and give your feedback. I am planning to write more and share more. Check for more in the upcoming posts.

    Monday, March 15, 2010

    Fix to Report viewer problems in IIS 7 or later

    When we migrate web applications from IIS 6 to IIS 7 or IIS 7.5, we will face some problems in http handlers, mappings etc. I faced some problems with reportviewer control. So, below are all problems I have faced and solutions to them. And one more thing is, the server to which we migrated the application may or may not have all the report viewer dlls available in the system. If they didn't install then we need to install them. Otherwise you will get compilation error as we are using that in our application.

    First of all, before proceed what are the dlls needed for the report viewer to run?
    Microsoft.reportviewer.common.dll
    Microsoft.reportviewer.processingobject.dll
    Microsoft.reportviewer.webforms.dll
    Microsoft.reportviewer.winforms.dll - For windows applications.

    Sunday, March 14, 2010

    Fix for Not able to connect to SharePoint 2010 server web sites through Visual Studio 2010

    Today, I started working on SharePoint 2010 server side object model to delete all the files from the document library using batch command. I have written all the code but, I failed to connect to the web site using SPSite class. I tried all combination like with server name, ip address and many more. Always I am getting the exception that "not able to connect to SharePoint site".
    This is the actual exception :
    "The Web application at http://nb16 could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application."

    Wednesday, March 10, 2010

    SharePoint 2010 release date announced

    SharePoint 2010 and Office 2010 release date announced and it will be on May 12, 2010. Read more about it here.
    http://blogs.msdn.com/sharepoint/archive/2010/03/05/sharepoint-2010-office-2010-launch.aspx

    Monday, March 8, 2010

    SharePoint 2010 Silverlight Client Object Model - How to use

    As part of the introduction series, I want to present the advantage of the client object model introduced in SharePoint 2010. There are great advantages with this model as it don't require SharePoint needs to be installed on the client machine. We just need to refer the client dlls which Microsoft SharePoint provides and based on them we will write code to communicate with SharePoint server. In this article we will go through Silverlight Client Object Model. If you want to know the other client object model types go here. ECMAScript and Managed client object models.

    To communicate with the SharePoint server in Silverlight context we need to give two client SharePoint DLL references to the silver light project.

    Sunday, March 7, 2010

    SharePoint 2010 Client Object Model - Managed Client OM - How to use

    After I have written nice posts on complete details on Client Object Model and ECMAScript introduction planned to write introduction posts on Managed Client OM and Silverlight Client OM. So, in this post, we will discuss on Managed Client Object Model.

    So, Managed Client Object Model is simple .NET code written based on CLR. So, you can use C#.net or VB.net to write code and execute whatever you want against SharePoint server.So, you can use any c# project to write code and run it. But, are there any prerequisites to write code? Do we need to follow some rules or process?

    First, to write client side code, we need SharePoint libraries which has all the methods and classes to communicate with the SharePoint server. For this reason Microsoft SharePoint 2010 provides us the client side dll's to write Managed code. Below are the details.
    DLL's needed: Microsoft.SharePoint.Client.dll, Microsoft.SharePoint.Client.Runtime.dll. Find these files in the 14/ISAPI folder. Usually, the location would be at "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI".

    Monday, March 1, 2010

    SharePoint 2010 LoadQuery Vs Load Methods

    In SharePoint 2010 we can speak about a year continuously about the new features and APIs. They have included plenty of things and should be made developer life easy!!!
    Here is a nice concept I want to tell to my readers about what is the difference between the load() and loadQuery() methods. The main definition both will use to load the data or objects you want from the SharePoint server. Then where is the difference?

    To reduce the confusion, first, we will discuss these in the Managed Client OM [C#].
    1. Difference in syntax:
    Managed Client object model supports two types of syntax in data retrieval process. One is Query syntax [Linq] and another is Method Syntax.

    Saturday, February 27, 2010

    SharePoint 2010 HTML Markup changes in rendering

    Wow. SharePoint 2010 has lot of new features. Everyone knows that. But, among all of them, the main thing I have really loved is the HTML markup generated for the SharePoint 2010. You know what? They have replaced the tables with Div and ul, li etc. So, this is a very good thinking and change from SharePoint team which likes by all and browsers. Everyone knows what are the problems with TABLES and in SharePoint 2007 you find many many tables. But not any more in SharePoint 2010.
    Below is the simple snapshot which is taken from the view source of SharePoint 2010 Publishing site template.

    Friday, February 26, 2010

    SharePoint 2010 ECMAScript - How to know logged in user information

    This is post which is simple and not really needed. But when I started writing the code in ECMAScript I have faced problems in getting the logged in user information. So, my readers may feel good after see this post and really most the users are looking for this too.
    By this time, we have really understood all about ECMAScript Client Object Model and debugging. So, it's easy for us to know it well.
    Please find the code below to get the current user information.
    <script type="text/javascript">
    ExecuteOrDelayUntilScriptLoaded(getWebUserData, "sp.js");
    var context = null;
    var web = null;
    var currentUser = null;
        function getWebUserData() {
            context = new SP.ClientContext.get_current();
            web = context.get_web();
            currentUser = web.get_currentUser();
     currentUser.retrieve();
            context.load(web);
            context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));
        }
        function onSuccessMethod(sender, args) {
            var userObject = web.get_currentUser();
            alert('User name:' + userObject.get_title() + '\n Login Name:' + userObject.get_loginName());
        }
        function onFailureMethod(sender, args) {
            alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
        }
    </script>
    
    So, the above code returns you the user object and displays user name and user login name. You can customize it as you want and please let me know the feedback or questions you have.

    SharePoint 2010 ECMAScript - how to know all methods in SP object and debug

    After spent good time to write nice posts on Client Object Model and ECMAScript how to use, I want to present you another nice tip on how we know all the methods and properties available for the SP object in the ECMA javascript . MSDN documentation is not finalized or completed yet to know what properties and methods  for SP objects have. And when you want to query something [like list or web] and you are not aware of what it has inside methods and properties, then the best way as far as I know is, using the Javascript debugging using Internet Explorer.

    SharePoint 2010 - Client Object Model - ECMAScript - Introduction on how to use

    In SharePoint 2010, the great feature is introducing the client object model [Read this article before proceed]. The great advantage with this is, we can do plenty of things without server side coding using the ECMAScript. There are plenty of default supported files to use and do whatever you want with the SP Package files. All javascript files will be found in the layouts folder. All of them starts with "SP" name.

    ECMAScript works only for the current context. It means from outside of the site, you can't access the SharePoint data. This won't support the cross-site scripting.

    How to add the reference to SP.js and access the data?

    Thursday, February 25, 2010

    SharePoint 2010 - Complete details about Client Object Model

    This is the introduction to the Client Object model introduced in the SharePoint 2010. This is going to be a huge help and useful part in SharePoint 2010 for developers and makes lot of customization to the existing SharePoint system.

    In eariler versions, I mean till SharePoint 2007 the code runs using the SharePoint object model to run against the server which is running SharePoint. Other than the SharePoint server object model, other way is, simply reference the web service and use that to get and manipulate data. Then what is the need of SharePoint 2010 Client object model[Cleint OM] concept?

    Wednesday, February 24, 2010

    Retrieving the COM class factory for component with CLSID {BDEADF26-C265-11D0-BCED-00A0C90AB50F} failed due to the following error: 800703fa

    This is a SharePoint 2010 BETA edition exception. Most of the people who are working with SP2010 should get this exception. Below are the exception details:

    Retrieving the COM class factory for component with CLSID {BDEADF26-C265-11D0-BCED-00A0C90AB50F} failed due to the following error: 800703fa.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {BDEADF26-C265-11D0-BCED-00A0C90AB50F} failed due to the following error: 800703fa.

    Workaround:
    1. Doing an IISRESET solving the problem but it is solving temporarily.
    2. Open IIS and go to your SharePoint site. And find the application pool.
    3. Go to application pool, click Advanced settings, change the value for "Load User Profile" to "true".
    That's it!!! You are done.
    Special thanks to Bassem Georgi for the nice tip.

    Tuesday, February 23, 2010

    JQuery 1.4.2 released

    These guys are very quick and fast updates in releases. Jquery 1.4.2 is released and they came up with strong version. This version again improved plenty of things in terms of performance and some events. Fixed lot of issues and bugs. So, get it and use it. Read the complete list of features on their site.

    http://blog.jquery.com/2010/02/19/jquery-142-released/

    Tuesday, February 16, 2010

    SharePoint 2010 site templates not showing in create site page, How to get them?

    This is a bit surprising to the people who are playing with SharePoint 2010 very first time. When we try to create subsites in the main site collection we need to pick the right site template and go. But, what if you are not able to see the list of site templates in the list?
    1. I have created a simple publishing site in SharePoint 2010 server and below is the screen which looks like by default.
       

    User profile import problems in SharePoint 2010

    I know, most of the SharePoint administrators and development team facing problems with importing or syncing up the active directory with user profile store or SSP in SharePoint 2010. There are many reasons and you need to read the complete documentation before do anything.

    I have initiated the thread in MSDN forums here and still that is growing. User profile import

    But, there are some configurations we need to check before do the user profile import. One of the important notes is "The farm is running either the Standard or Enterprise version of SharePoint Server 2010 and you have run the farm configuration wizard. Profile Synchronization does not work on a stand-alone installation for SharePoint Server 2010 Beta."

    JQuery conflict when using different javascript libraries

    Today, I came to a scenario where I need to use JQuery and Prototype libraries in my application. Both are operating with $() to access the objects and do the client side logic. But, the $() is getting conflicted between JQuery and Prototype libraries and things got messed up. So, it should be a good practice to distinguish them because who knows what requirements come in future and how many client side javascript technologies we are going to use. The code which we have shouldn't effect anything, right?.

    The same thing happen in my SharePoint sites too. When I tried to migrate from SharePoint 2007 to SharePoint 2010, the client side script [JQuery] custom developed is not working. The only reason behind is the conflicts in the javascript. The file SP.js in the SharePoint 2010 causing the problem.

    So, make sure, if you have used JQuery in your applications, always the best practice is declare the Jquery global instance variable and then start using that instead of directly use the $(). For example,
    var $j = jQuery.noConflict();
         
         // Use jQuery via $j(...)
         $j(document).ready(function(){
           $j(".someclass").hide();
         }); 
    
    
    So, in the above code, we actually referring the $j() instead of directly $(), so it won't give any problems in future. No matter what how many different client side javascript technologies used, that should work. For more information check it here.

    Hope you like this post and love to hear comments.

    Monday, February 15, 2010

    SharePoint Exception: No item exists [url]. It may have been deleted or renamed by another user.

    This is one of the exception regularly comes when we do custom development and create custom aspx pages. Everything works fine and no code issues but still this exception comes. I worked hard to fix this problem so long time. Tracked everything like logs, event viewer and more tips. Nothing helps. Then  spent some nice time and trail and error methods found the problem and fixed.

    More details about exception:
    No item exists at http://mysharepointsite/Pages/Home.aspx?id=4&q=HQ.  It may have been deleted or renamed by another user.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: Microsoft.SharePoint.SPException: No item exists at http://mysharepointsite/Pages/Home.aspx?id=4&q=HQ.  It may have been deleted or renamed by another user.

    SharePoint Exception: Coercion Failed: Input cannot be null for this coercion

    This is the exception, I am seeing very first time in SharePoint development. What I tried was, through SharePoint designer I tried to update the list item. The source and destination lists are having a field of type choice. I want to grab the choice field information from source list and update the destination list choice field.
    The problem occurs only when the source choice field is empty.

    More clearly, I have a list with checkbox list field. When a new list item is added, the workflow triggers and start updating the another list item with the current item information. And when I select nothing in the checkbox list field, then it throws the exception "SharePoint Exception: Coercion Failed: Input cannot be null for this coercion".

    So, why the problem comes?
    Because in update list item phrase in SharePoint designer I have selected the lookup for choice Return field as as Choices, Comma delimited. See the below screenshot.
    Once changed that back to the As String then everything worked perfect. But, didn't get the reason behind. When nothing selected, then it shouldn't do any operation. It should check for null and do nothing. May be a built-in problem or something interesting with this.

    Hope this helps to understand it well and solve your problem.

    Friday, February 12, 2010

    Declarative workflows cannot automatically start if the triggering action was performed by System Account

    This is the exception came to me today when I try to run a workflow on a list when an item is created. I tried different combination and didn't get the problem resolved. Even I removed all workflow conditions and actions and placed a simple update like update the title of the item in workflow body. Still that didn't give me the result. The workflow  is not starting at all automcatically.

    After some research found that, when we are using system account [With the account we installed SharePoint], the workflows won't run automatically. This is looking crazy but that is what the problem. When I try to run them manually, then they are running absolutely fine, but they aren't starting automatically.

    When I try to login with another account other than system account, no problems. Workflow starts automatically. The only reason is "if we install SP1 package, then declarative workflows can no longer be triggered by the SharePoint System account" as there is the possibility of security vulnerability. So, they didn't give access to run the declarative workflows under the System account.

    So, friends, if you face any type of these problems make sure you login with some other account other than system account. Hope this helps to save at least 2-3 hours of time.

    Team Explorer 2008 and TFS 2010

    Can we connect to TFS 2010 from Team explorer 2008? This is the question to most of the people who want to use TFS 2010, but, they don't have VS 2010 installed by chance. So, no need to bother. Visual studio 2008, Team explorer 2008 supports it and you can connect to 2010 TFS server. But, you need to install one package for the forward compatibility for VSTS 2008 version. You can download it here.
    Visual Studio Team System 2008 Service Pack 1 Forward Compatibility Update for Team Foundation Server 2010 (Installer)

    But, before you install it, make sure you have installed the VS SP1 and Team Explorer SP1.
    Visual Studio SP1 and Team Explorer SP1

    Before you install anything, please read the article to avoid problems.
    Installation order of packages

    That's it!!!

    Monday, February 8, 2010

    ASP.NET Checkbox click on label calling click event twice in JQuery

    I don't know this is a known issue in Mozilla Firefox browser. When I use ASP.NET checkbox on a web page, it will render as a input control plus label. So, when I click on checkbox or label the click event raises and checkbox  state changes. But, I figured out  a strange behavior. When I click on the label the click event is raising twice when I use JQuery [I didn't try with  javascript]. But, where as when I click on checkbox it is raising click event only once. How to solve this problem? I have tried so many ways to solve the problem. But, didn't success.
    I have tried by using type of the control. If type is checkbox then only go inside or just do nothing. When I click on label, it is coming to click event and every time, all lines are executing. I don't know why this is happening. Wheat I understood is, when we click on label then internally it is again generating click event for the checkbox because of the label for attribute. So, take care of it.
    And if you find any solution to this problem, please let me know.

    JQuery 1.4.1 released

    It's a good news for all JQuery lovers. The latest version of JQuery 1.4.1 has been released and getting very popular. Personally, I feel very good. The secret of success this version is the performance improvement, some changes to existing methods and new additions. This is very nice to know the functions are executing less time than they were.
    You can link the JQuery files from Google servers from this location.
    http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js
    They have made plenty of changes to setter, getter and ajax methods.
    The whole API changes are documented here.
    http://api.jquery.com/category/version/1.4/

    Why to wait, get the latest version and start playing with it.

    JQuery live() method for Focus and Blur

    Everyone knows these days we are liking the client side implementation as much as we can. That is the only reason why all the client side languages are more popular. In Jquery, Live() method is very nice concept and as we know it is not supporting all the events. [Hope in version 1.4.* it is coming.] I had a requirement to raise an event when user goes away from the input control and that input controls are dynamically generated. But, as we know, we don't have live() method support for blur and focus events, we need to simulate or write our own. Below is the best way to implement that.
    http://stackoverflow.com/questions/1199293/simulating-focus-and-blur-in-jquery-live-method
    This is very easy and simple to understand. The same way, we can implement the other events we needed. Hope this helps and will do much with JQuery.

    Friday, February 5, 2010

    SharePoint Querying - CAML Query usage when special characters in DATA

    We have many ways of pulling information from SharePoint sites. Depends on the requirements we may use web services or using SharePoint object model. If you have requirement to filter data from a SharePoint list then the best option is through CAML queries we will write a simple query and run it against the SharePoint list and get the collection of data. So, if you are familiar with CAML queries then no need to say how to write and how they will execute. But, this post main focus is on what if the data which you are querying contains the special characters like '&'. The query won't run and it fails. Take the example of below code.
     <Where><Contains><FieldRef Name='Description' /><Value Type='Note'>Praveen&Battula</Value></Contains></Where>
    
    The above query will leads to errors and you see the error in the logs. So, what is the problem? There are no syntax errors and everything is perfect. But, where is the problem? The problem is as we discussed the symbol '&' in the data [Praveen&Battula]. So, how to solve this problem? Below is the simple solution.
    <Where><Contains><FieldRef Name='Description' /><Value Type='Note'><![CDATA[Praveen&Battula]]></Value></Contains></Where>
    

    I think, by seeing above syntax, you may get the answer. :). What I did is, we are familar with XML and we know how to handle special characters in XML[Using <![CDATA[Some DATA]]>]. So, I used the same logic here and everything started working as expected.

    **UPDATED**
    From the comments, I found a special scenario of why it fails even we use CDATA. Check it below.
    http://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/8b442d22-eb56-40d8-a487-a325d3a70626/
    I am trying to solve this, but for now, the only solution is through encode it and query it.

    Please let me know, your ideas on it.

    Monday, February 1, 2010

    SSRS Reports get Month name from Month Index or from date

    This is one of the small tips which I want to tell my readers. When you work with SSRS reports, you may come across with the requirement like, you know the index of the month, but you want to print month name from it. So, if that is the situation for you, this is the right post for you. :)
    MonthName(monthindex) 
    You may get it from t-SQL as I mentioned in my previous post here.
    But in SSRS reports the way you  need to approach is like this.
    1. Take a textbox to report body.
    2. Write the below syntax into it [As you know, it is the expression].
    =MonthName(7)

    In any case, you need to get it by date then you still use this below function.
    =MonthName(Month(Fields!datefield.Value))
    

    Hope this helps and please let me know, if you face any problems.

    Tuesday, January 26, 2010

    JQuery merge or combine two tables into one

    Hi, this is something interesting isn't it? But, this is what my requirement. I will tell you in detail. I have a gridview on my page and another table with the same number of columns. Grid view is for showing and updating data. And I have one extra table for adding a new record. This table immediately follows the actual grid view. The extra table named the class as "tableAdd". So, user sees the gridview header and enter the data into the tableAdd row and hit save button and gridview will refresh and shows up the newly created record.

    But there is a problem in look and feel. Because both are in different tables, when the browser width changes or resolution changes the columns in both tables are not in sync, even if they have same columns and same width. So, how to make them sync? Then I got an idea to implement a solution  using JQuery. So, I planned to grab both tables on client side and merge them into one.

    <table class="gridview"><tr><td>col1</td><td>col2</td></tr></table>
    <table class="tableAdd"><tr><td><input type="text" /></td><td><input type="button" /></td></tr></table>

    Now, above are two tables I have and now I need to merge them into one and delete the second table from the DOM.

    $(".gridview > tbody:last").append($(".tableAdd > tbody").html());   
    $(".tableAdd").remove();

    Hope, you understood it well and may helps in some scenarios. Please let me know, if you have any problems.

    JQuery Append a table row at first and last positions of a table

    This is something you need to know when you have some requirement to add rows to table on client side using some java script technology. I have chosen JQuery and the requirement is, I need to add the rows at first and last of the existing table. Below is the way to achieve that.

    Add as first row of a table:
    $(".gridview").prepend("<tr></tr>");
    Add as last row of a table:
    $(".gridview > tbody:last").append("<tr></tr>");

    I think, you feel it's simple. Yes it is easy and helps in solving some issues. And remember the class gridview I have used in this example, is the table class name. And the string "<tr></tr>" is the actual table row content.

    Hope this helps and let me know, are there any better ways to implement the same.

    Sunday, January 24, 2010

    Do not allow HTML into the textbox

    This is the most of times QA team will try to do and file bugs in web applications. They tries to enter the HTML into the textbox and the request fails as usual. The page renders with an .net generic exception if it is asp.net web application. This is because of the security problems. ASP.NET [OR I am not sure how different languages treat the html in textbox] if any HTML in the input textbox then it treats that it as "script injection attack".
    If you think that the web application is safe to enter HTML tags in the input controls then there are two solutions.
    • For the specific page, I mean in the page directive just add extra attribute ValidateRequest="false". This will apply to only that page, so you can enter HTML into the text boxes for that page.
    • If you want to solve this problem for all pages in the application then in the web.config file, add ValidateRequest="false" for <pages> tag.
    But, as we discussed this is not the 100% true solution, because there are chances of script injection attack. So, how to solve this problem? Today these days, everyone started using javascript or JQuery in their web applications. I have chosen JQuery to fix this problem. Below is the solution.
    $(document).ready(function() {
    $("input").live("keyup", function() {
    RemoveTheHTMLFromTextBox($(this));
    });
    $("input").blur(function() {
    RemoveTheHTMLFromTextBox($(this));
    });
    $("input").live("click", function() {
    RemoveTheHTMLFromTextBox($(this));
    });
    function RemoveTheHTMLFromTextBox(obj) {
    var inputValue = $(obj).val();
    if (inputValue.indexOf('<') > -1 || inputValue.indexOf(">") > -1) {
    $(obj).val($(obj).val()
    .replace(/"/g, "")
    .replace(/</G, ??)
    .replace(/>/g, "")
    .replace(/&/g, ""));
    }
    }
    });

    This will look for any HTML tags [<>] and replace them with empty space. This solution will work perfectly. Hope you like it. What is your opinion? any best solution?

    Note: Don’t forget to add the JQuery file before you access this script.

    How to check JQuery object is null

    This is simple and no need to write post for it. You may feel same right? But, this is the question I received from almost 10 people till now. So, I thought of writing a post on it. So that, it may help people who are looking for the same through out the world.

    By default JQuery returns object when you declare $("$id") or $(".class"). If you write code for it as below, then that's wrong.

    if($("#id") != null)
    {
    //Write code if the object is not null
    }
    
    if($(".class") != null)
    {
    //Write code if the object is not null
    }

    If you write the above code for checking null condition then if condition always success and will execute code inside of the if condition. So, the correct solution is,

    if($("#id").length > 0)
    {
    //Write code if the object is not null
    }
    
    if($(".class").length > 0)
    {
    //Write code if the object is not null
    }

    It tries to find all objects which has the given id or class and if any exists then the length will be equal to the number of times the id or class occurred. So, if the length is zero then it's nothing but the id or class don't exist and the object is null.

    Hope, this solved your problem and this is a new tip for today. Is this helpful?

    Sunday, January 17, 2010

    Refresh intellisense local cache in Sql Server 2008

    Everyone knows that Sql server 2008 has an excellent feature for supporting the intellisense. This will surely fasten the development. Last week, I have created 3 tables in my Sql server 2008 and when I try to write the stored procedure based on those tables, surprisingly they weren't shown in the intellisense any more. I thought initially it's a bug in Sql Server 2008. Lately after done some research and found that we need to refresh the cache for intellisense to shown up everything correct. Please find the below article which is more helpful and detailed.

    http://cherupally.blogspot.com/2009/12/how-to-get-sql-server-2008-intellisense.html

    Saturday, January 16, 2010

    Report viewer control authentication – Part 2 – Forms Authentication

    If the reporting services configured to use forms authentication and you need to show the reports in the custom developed applications then the need of processing authentication the report viewer control through the code.
    Report viewer control authentication using windows authentication is described in the part 1 here. Now, we will discuss the authenticating forms authentication through C# code.
    If we are are developing windows application and want to use report viewer control, then we need to implement the below logic to authenticate.
    reportViewer1.ServerReport.ReportServerCredentials.SetFormsCredentials(null, "userName", "password", "");
    this.reportViewer1.RefreshReport();
    Where as in forms authentication simply assigning the credentials not enough. The reasons behind are, security, code efficiency, performance, response time etc everything come into the picture. So, we need to write code which supports everything.
    What are the major tasks?
    • Report viewer control excepts the credential of type IReportServerCredentials. So, we need to create an object which inherits from this interface and pass this to the report viewer control to authenticate.
    • Handling cookie. Based on the login and request is successful we will write the cookie to browser and keep that in browser for further requests processing. The advantage is if cookie is available then won’t make any request to report server for authenticating.
    • To create the cookie related information we actually need of hijack the request and response and get the cookie information and save it to browser. So, how to catch the request and response which made to report server? We will discuss this later in this article.
    • To actually communicate to the report server, we need to make the communication with it. The best way to do that is using web services. Everyone knows that reports in SSRS gets with two sites. One is report manager means report web application [/reports] and the report server means a report web service[/reportserver]. So, we will use the web service, write a proxy and implement the existing functions in it.

    Friday, January 15, 2010

    Report viewer control authentication – Part1 – Windows Authentication

    Report viewer control, I think everyone knows what it is and how to use it. Today, I want to tell you how to authenticate the report viewer control in ASP.NET web application or windows application.

    The report viewer control passing the credentials is same in both windows and web applications. How to pass windows credentials to the report viewer control?

    • Either you can set the <identity impersonation="true" /> or
    • You can directly pass the credentials object to the report viewer control as shown below. If default credentials then
      System.Net.ICredentials credentials = System.Net.CredentialCache.DefaultCredentials;ReportServerCredentials rsCredentials = serverReport.ReportServerCredentials; rsCredentials.NetworkCredentials = credentials;

      But, in some scenarios, you may need to pass the windows credentials dynamically instead of the logged in user credentials. Then it's the time to use NetworkCredentials object. Check below.

      ICredentials credentials = new NetworkCredential("User name", "Password", "Domain");

      Now, assign this credentials object to the report viewer credentials. So, I prefer to not directly give the credentials directly in the code. Instead add them in the web.config and access them in the code.

      I think, you understood it well. Love to hear comments.

    Sql Server reporting services and Forms authentication – Part 3 – Linking aspnetdb to report server

    I think, you have read my previous two posts related to implementing forms authentication in report server.

    Sql server reporting server and forms authentication – Part 1 – Understanding the concept.

    Sql Server reporting server an forms authentication – Part 2 – How to implement.

    I just followed Russell’s article to link sql server report server to aspnetdb. So, I prefer to redirect my users to the same post. I don't want to repeat the whole story here again. So, please go here and continue your reading.

    http://blogs.msdn.com/bimusings/archive/2005/12/05/using-sql-reporting-services-2005-and-forms-authentication-with-the-whidbey-2-0-sqlmembershipprovider.aspx

    Hope with this post, you are completely done how to use, implement and linking the default aspnetdb to the report server in forms authentication.

    Sql Server Reporting services and forms authentication – Part2 - How to implement?

    Before continue this post, please read the post understanding the concept forms authentication in sql reports – Part1. The implementation of the process is so simple.

    • Microsoft team already given a sample application which has the forms authentication enabled.
    • They have written some code which has a security extension with login pages.
    • To understand it well or to implement just do this. Go here and download the sql server samples from Codeplex. http://www.codeplex.com/SqlServerSamples/Release/ProjectReleases.aspx?ReleaseId=4000
    • The file SqlServerSamples.msi contains all the example types for sql server.
    • Download the file and start installing them.
    • After installed the file successfully, go to the location where it installed [Usually if it is sql server 2005 then the location would be C:\Program Files\Microsoft SQL Server\90.] and the folder named "samples".
    • And in the samples folder we need to consider the sample "Samples\Reporting Services\Extension Samples\FormsAuthentication Sample".
    • This sample has all the code we needed.
    • Now, before proceed open the Readme file found in the location mentioned above.
    • This is the time we actually start the implementation. Please do as is mentioned in the readme file without anything missed.

    The above process will take around half an hour to configure everything correct. And if we do everything correct, then you are able to see the report server running using forms authentication.

    What to remember while implementing the process?

    • The connection string in the sample code. The sample code contains has the connection string as shown below.

      using (SqlConnection conn = new SqlConnection("Server=localhost;" +
                    "Integrated Security=SSPI;" + "database=UserAccounts"))

    • So be sure you installed the useraccounts database in the default instance of the sql server and the windows account you have logged in has access to it.

    Now, you have everything installed and setup the forms authentication in sql server reports.

    Hope you enjoyed the post. Please let me know your feedback and any questions if you have.