Preview: Rare Solutions in SharePoint, C-sharp, ASP.Net, JQuery, SQL SERVER
Rare Solutions in SharePoint, C-sharp, ASP.Net, JQuery, SQL SERVERRare Solutions... Complete information on SharePoint, TFS, ASP.NET, Sql server, Visual Studio, C#, Java script, CSS and more. This blog aim is to share knowledge and solutions to all the problems I faced and how I solved by my experience.Updated: 2010-02-09T17:41:07.377+05:30
Links for 2010-02-08 [Digg] 2010-02-09T00:00:00-08:00
ASP.NET Checkbox click on label calling click event twice in JQuery 2010-02-08T16:43:03.530+05:30 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.* released 2010-02-08T16:28:46.408+05:30 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.
http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min 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 2010-02-08T10:21:19.109+05:30 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.
SharePoint Querying - CAML Query usage when special characters in DATA 2010-02-08T17:45:50.351+05:30 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.
SSRS Reports get Month name from Month Index or from date 2010-02-01T16:46:38.279+05:30 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.
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.
JQuery merge or combine two tables into one 2010-01-26T03:14:49.299+05:30 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.
JQuery Append a table row at first and last positions of a table 2010-01-26T02:53:41.533+05:30 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("Add as last row of a table: $(".gridview > tbody:last").append("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 " Hope this helps and let me know, are there any better ways to implement the same.
Do not allow HTML into the textbox 2010-01-24T15:59:39.519+05:30 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
How to check JQuery object is null 2010-01-24T15:49:46.088+05:30 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? [...]
Refresh intellisense local cache in Sql Server 2008 2010-01-17T13:52:59.935+05:30 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
Report viewer control authentication – Part 2 – Forms Authentication 2010-01-24T16:19:22.965+05:30 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. I think, it is little bit complex to understand the above tasks. But actually they are very simple to implement. Code needed: We need two classes to get what we need. These are custom classes and add them in single file named ReportServerCredentials.cs somewhere in the project. Classes needed - ReportServerCredentials and ReportingService. public class ReportServerCredentials : IReportServerCredentials{private Cookie m_authCookie;public ReportServerCredentials(Cookie authCookie){m_authCookie = authCookie;}public WindowsIdentity ImpersonationUser{get{return null; // Use default identity.}}public ICredentials NetworkCredentials{get{return null; // Not using NetworkCredentials to authenticate.}}public bool GetFormsCredentials(out Cookie authCookie,out string user, out string password, out string authority){authCookie = null;user = ConfigurationManager.AppSettings["ReportServerUserName"];password = ConfigurationManager.AppSettings["ReportServerPassword"];authority = "";return true; // Use forms credentials to authenticate.}}public class MyReportingService : rsExecutionReference.ReportExecutionService{private Cookie m_authCookie;public Cookie AuthCookie{get{return m_authCookie;}}protected override WebRequest GetWebRequest(Uri uri){HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);request.CookieContainer = new CookieContainer();if (m_authCookie != null)request.CookieContainer.Add(m_authCookie);return request;}protected override WebResponse GetWebResponse(WebRequest request){WebResponse response = base.GetWebResponse(request);string cookieName = response.Headers["RSAuthenticationHeader"];i[...]
Report viewer control authentication – Part1 – Windows Authentication 2010-01-24T16:27:31.096+05:30 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
Sql Server reporting services and Forms authentication – Part 3 – Linking aspnetdb to report server 2010-01-15T20:27:05.672+05:30 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? 2010-01-15T20:17:44.659+05:30 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. [...]
Sql Server reporting services and forms authentication - Part1 2010-01-15T18:49:30.260+05:30 Till now, I know Sql Server reporting services supports only Windows authentication. And of course till now What I did for all clients is the same. The roles or access everything will define using the default report manager site and deploy that on the client environment. But, the current project I am working on is completely different and the main requirement is enabling forms authentication in the sql server reporting services. The story behind is, the client is running different applications based on the aspnetdb [Forms authentication]. So, they want us to run the report server using forms authentication based on the same database. So, how to achieve that? This was the question in my mind till last week. After done research about two days found some nice articles and the way to achieve that. So, I thought of explaining the research, analysis and the way we need to proceed in this article to my readers. So, if you have any requirement like this in future just go ahead and start the work in the same process as explained below. This Part1 describes all about understanding the concept. To understand the concept: Using forms authentication in reporting services: http://msdn.microsoft.com/en-us/library/aa902691%28SQL.80%29.aspx Here you need to understand one thing that Reporting services in SQL server which comes by default only supports Windows Authentication. There is no default way to make it or turn on forms authentication. To do this, we need to make some custom configurations, changes to web.config and custom coding. But, nothing to worry. It's easy. :) Reporting services are developed to be extensible. You can write your own extensions and deploy or integrate them to reporting services by making some changes to their config files. So, now we need to concentrate on what is a security extension? Before proceed we need to understand some key points: Reporting services uses role-based security system to authorize users. Security extension supported is based on an open and existing API. Use custom defined authentication or forms authentication if any only if, you need to define different users and roles which is not based on windows accounts. Read the security extension API in the documentation given in the above link. This has all the classes and interfaces defined to start coding. Now, what is the security extension. "A Reporting Services security extension enables the authentication and authorization of users or groups; that is, it enables different users to log into a report server and, based on their identities, perform different tasks or operations." So from this post I hope you understand what we need to do to enable forms authentication in reporting services. [...]
Sql Server Reporting services 2008 Tablix control 2010-01-17T15:28:50.939+05:30 When working with Sql server 2008 reporting services I found a new control named Tablix. [Of course there are plenty of new features] This is a mix of both Table and a Matrix. The main and great advantage of it is when we drag a table or matrix to the report body you can't find table or matrix any more. The report control automatically convert it to Tablix. Now, it's very easy to show the complex and grouping of data with this control. The interest thing in 2008 reporting services is, When I open report builder 2008, BIDS 2008 I didn't find the Tablix control at all and started researching for the control. Stupidly searched in google like download tablix control ssrs 2008 etc… But, once I drap and drop the table or matrix and right clicked for properties found "tablix properties" in list of properties there. Then understood the whole concept and implemented the reports very fast. Hope this post will help you understand it. Let me know what you think. [...]
Sql Express instance is not in the list of network servers 2010-01-15T13:23:43.303+05:30 Today, I have a requirement to work with SQL Server express. So, I setup a server with Sql server express installed and configured everything we needed. My team has 4 developers and everyone should access the sql server express to run the project. But, when they try to access the sql server express instance the server is not responding and always it results an error. When I open network servers, I found only the instances of my sql sever and in that list I didn't find the new sql server express I have setup on the server nb11. See the below screen. So, This stop us working together and started finding what's the problem. I logged into nb11 machine and checked all the services related to Sql Server and found Sql Server Browser status is stopped. Because of this, it is not able to expose to external environment or outside of the server. So, the solution is just start running the Sql server browser. Now, go to list of server in network servers and you started seeing the nb11 express instance there. Now, the question is what is Sql Server Browser? Simple definition is "Provides SQL Server connection information to client computers." Hope you like this post and please let me know, if you have any questions. [...]
Report project template in Visual Studio 2010-01-15T13:08:47.151+05:30 This is the question most of the people asking. So, just thought of posting it for my readers. Report project template is associated with the reporting services in the Sql server. This template is not an addin to visual studio or a specific download won't be available. You will see the template if and only if you install client tools while installing the Sql Server. So, to get that template, open the sql server setup file and select the client tools option from the list of features available. That's it!!! Let me know, if you have any issues to questions.
Disable button in onclick and process the button click event 2010-01-24T16:34:30.030+05:30 This is what I need to implement for one of my project. I am using Ajax and if user tries to hit the submit the button more than once, only the very first request should submit to server and all other requests shouldn't make any request. So, for this I need to disable the button when first time click on button and enable it after processed. But, I faced a problem that when I try to disable the button in javascript of client side click event then the postback event not raising at all. There are couple of ways we can implement this. First, I tried from server side code.Solution 1:btnSubmit.Attributes.Add("onclick","javascript:" + btnSubmit.ClientID + ".disabled=true;" + this.GetPostBackEventReference(btnSubmit));But, this solution won't work in all scenarios and especially if there are validations. Solution 2:OnClientClick='javascript:this.disabled=Page_ClientValidate("");' UseSubmitBehavior="false"For ASP Button the two properties onclientclick and usesubmitbehavior will do magic for us. In onclientclick event I am disabling the button if and only if the validation passed. Go back to my previous post. It describes how to validate the controls in client side and give the result true or false. And because of using the UseSubmitBehavior property it will automatically re-enable the button once the request processed.Hope this gives you the enough idea. Like to know what you think. [...]
Links for 2010-01-12 [Digg] 2010-01-13T00:00:00-08:00
Data Formatting in sql server reporting services 2010-01-07T00:54:27.372+05:30 In Sql server reporting services the formatting the data is pretty much simple as we have plenty of built in options available for percentage, numbers, decimal, currency etc. So, just them to data format and display the data as you want. Below are most commonly use format for the usual reports. c – Currency d – Decimal n – Number p – Percentage. If you want two decimal places in decimal number then in the format option [Text box properties -> format] then the format should be d2. In percentage if you want two decimal places in percentage then the format is p2 etc.. But, I have tried it some reports, and found not working. Then used the default C# string formats for the data formatting in reports. That is, for two decimal places the format is like 0.00. Then the result data will be two decimal places. Example, 5.67. So, you can try both and use which one is best fit for you. There are other plenty of formats available and they are completely described here. http://msdn.microsoft.com/en-us/library/ms252080%28VS.80%29.aspx This help you to understand the data formatting in SSRS. What do you think? [...]
Fix to Divided by zero problem in Sql server reports 2010-01-24T16:37:04.097+05:30 When we work with reports, most of the times we need to do complex calculations and logic. When we do calculations, there are chances of using the division operation. So, need of checking the divided by zero problem every time. So the solution I propose is, write a simple custom function and call it wherever needed. For every report there is a part called Code and there we can write the custom VB code. Public Function CheckDividedByZero(ByVal param1 As Double, ByVal param2 As Double) As Double If param2 = 0 Then Return 0 Else Return param1 / param2 End If End FunctionSo, call this function wherever you are performing the division operation. Hope this will solve your problem and you never face the divided by zero problem any more. [...]
Date formatting in Sql server reporting services 2010-01-24T16:40:25.461+05:30 When we work with reporting services, we come across with different requirements to display the date in different formats. So, we need to know the formats we can give to get required value. Sql server reporting services supports different formats as T-sql and C# does. So, I just want to give the valid formats I use to display the date in required format. =Format(Fields!DateCreated.Value, "M/d/yy") - 3/14/1986=Format(Fields!DateCreated.Value, "d-MMMM-yy") - 14-March-86=Format(Fields!DateCreated.Value, "MM/dd/yyyy") - 03/14/1986=Format(Fields!DateCreated.Value, "M/d/yyyy H:mm") - 3/14/1986 22:10=Format(Fields!DateCreated.Value, "dd-MMM-yyyy") - 14-March-1986=Format(Fields!DateCreated.Value, "MMM-dd-yyyy") - Mar-14-1986=Format(Fields!DateCreated.Value,"dd-MMM-yy") - 14-Mar-86You can try different combinations of above to get desired output. Hope this helps and love to hear the comments. [...]
Scheduling jobs in Sql server Express 2010-01-06T23:59:26.672+05:30 I know, at some point you need this when you use sql express. Sql express is the limited edition of Sql server. So, it doesn't contain all the features. To schedule we need sql server agent service. But it comes only with sql server. So, creating jobs are not possible with sql express. So, is there any way? Yes. Today I found a nice article on it. And that is perfect. Take a look at it and let me know your ideas on it. http://www.sqlteam.com/article/scheduling-jobs-in-sql-server-express Hope you like this article. Don't you?
Links for 2009-12-30 [Digg] 2009-12-31T00:00:00-08:00
IIS 7 – Managed pipeline mode – Global.asax redirect not working 2009-12-28T19:26:21.294+05:30 I installed Windows 7 and I really like it. I migrated all my applications from my old machine to new. And my old machine is running WS 2003 [iis 6] and new machine is Windows 7 [IIS 7]. In all applications everything ran successful except one. I implemented exception handling in my application. I have Global.asax page and in the Application_Error event, I log the exception details and redirecting the user to the error page. Whenever there is an exception in my application the page never redirect to the error page, it stays there in the same page with exception details on the screen. The same code ran very successful on my old server and in Windows 7 it's not. I just started thinking what could be the issue. The analysis went in this way. Code not changed, DB not changed and the only part changed is the IIS. Windows 7 has IIS7. So, The problem would be either the isapi dll or the application pool. So, started researching on those and found interesting points. In IIS 7, application pool has a separate feature named "Managed pipeline mode". This will tell the pool the pipeline mode. [which is of type sint32 in c# and the possible values for it are 0 and 1.] 0 is managed pipeline runs in integration mode. 1 is managed pipeline runs in classic or ISAPI mode. [IIS 6]. In Classic mode, managed application events are executed by using ISAPI. In Integrated mode, ASP.NET request processing integrates directly into the IIS 7 request-processing pipeline. Integrated mode enables you to configure managed modules for Web sites that are developed with unmanaged code. So, to work your logic correct, go to your site and see under what application pool your site running. Now, go to that application pool, properties and change the pipeline mode to classic mode. Now, you see everything works fine and the page starts redirecting to error page when any exception in your application. For more details: http://msdn.microsoft.com/en-us/library/microsoft.web.administration.managedpipelinemode.aspx Hope this helps and new tip today. Do you like this post? [...]
SharePoint timer job and settings or configuration file 2009-12-27T23:27:01.203+05:30 I got a question that what is the case when a SharePoint timer job needs a configuration file? Because, I really need the configuration settings for a timer job which I deployed. Because I got a requirement where I need to use the web service in a timer job and it needs the httpBindings and the endpoints. I can't place them in web.config of the web site as I can't access it here. But, I can access the web.config file as I discussed it in my previous post. I can get all the bindings and endpoints from web.config and create a c# bindngs object. And for the web service I passed the binding and that didn't solve the problem. Somehow, I got the below exception. WSE012: The input was not a valid SOAP message because the following information is missing: action. So, I started thinking in different ways and out of box. Below is the way how I approached towards the solution. Everyone knows that all the timer job runs with the help of the OWSTIMER.EXE. If you take a look at the console application, c# project and if you add the app.config file to the project then in your bin folder, you will see two files like if it is c# project then projectname.dll and projectname.dll.config and if it is console application then projectname.exe and projectname.exe.config. So, what you understood from it? for dll or exe there is associated config file if that project contains app.config file. What will happens when we use the dll or try to run the exe, the related config file also loads into memory and you can use the config file in the dll or exe. There my thought starts and I want to repeat the same concept for the OWSTIMER.EXE too. Find the location of where OWSTIMER.EXE is reside in. Generally, the location is at "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\OWSTIMER.EXE". So, go to that location and create a file named OWSTIMER.EXE.CONFIG. Open it in notepad and place all the settings code in it. Save it. Now, it's time to restart the timer service. So, go to services and find SharePoint Timer Service. And restart it. Now, run the timer service and you see everything is running successful. I mean all the settings will be loaded and run. Note: Try to include all the settings in the config file within these tags. |
||||||||||||||||||||||||||||||||||||||||||||||