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.