Posts

Showing posts from 2009

Asp.Net Save File on client machine

Recently I had a task to save file on client machine. We usually save file on server and in ASP.NET the more familiar task to save on client side was to export gridview results to excel file. This time the task was to save an image on client machine. Following is the code that I followed.   <pre name="code" class="html"> byte[] fileBytes = File.ReadAllBytes("D:\\Projects\\TestClientDownload\\images\\banner_ad_1.jpg");        Response.ClearContent();        Response.ClearHeaders();        Response.ContentType = "text/plain";        Response.AppendHeader("content-disposition", "attachment; filename=" + "banner_ad_1.jpg");        Response.AppendHeader("content-length", fileBytes.Length.ToString());        Response.BinaryWrite(fileBytes);        Response.Flush();        Response.End(); </pre>

Alert : can not set credentials for principal sa

  While editing credentials of database user, you may get this error in Sql Server 2008 management studio. It is just a checkbox that needs to be checked to resolve this issue. But this may save your few minutes finding the issue cause. Here is a great link for resolving this issue – http://weblogs.asp.net/atlaszhu/archive/2009/08/08/alert-cannot-set-a-credential-for-principal-sa-when-trying-to-modify-sa-properties-through-sql-management-studio-2008.aspx Technorati Tags: sql server , login

Apply CSS Class based on Browser

  Do you need to modify couple of CSS class attributes depending on browser?   There are various ways to achieve it. But I found this very simple approach for working on this issue.                 There are modifications needed at 2 places in the code. One is in the HTML body / ASPX page and other is in CSS file. Suppose there is DIV in your mark up and you want to apply different CSS class attributes if browse is IE6 / IE7/ IE8. Then just add a container div with id IE7 to this div. It can be added as this on ASPX page (Note- you can add this in Master page / specific page if you are not using Master Pages): - <!--[if IE 7]><div id="ie7"><![endif]-->       <div class=”category”> This is div of interest where ie7 specific rendering should be done.       </div>   <!--[if lte IE 7]></div><![endif]-->                 The second change is in CSS file. All classes which should

Optimized way to get count of rows from a table

  To get no. of rows from a table we usually use query Select count(*) from table_name But this query reads complete table to return no. of Optimized way for performing this query is Select rows from sysindexes where id= Object_Id(‘table_name’) Technorati Tags: Sql Sever

Get Unused Stored Procedures from Sql Server 2008

While working in projects, I always used to wonder about maintaining Stored Procedures in Sql Server. The way in which we organize them is that we go on adding the required stored procedures with some name convention so that we can identify what is the module to which this SP refers. But as the project goes ahead modifications come, we go on adding required Stored Procedures and some Stored Procedures become obsolete because of business rule changes. But as far as I have observed in IT projects, these stored procedures are kept as it is and when the project completes no one has any idea about which Stored Procedures are currently in use and which are obsolete. But I have come across this post , which shows how to get probably unused SPs from Sql Server 2008. The query is as follows, which returns SPs which are not in procedure cache. //The first part gives list of all SPs and also works in SQL2005 Select p.name From sys.procedures as p wh

Adding Javascript In Amazaon mTurk Form

  Adding JavaScript to mTurk form is possible and very simple. The difference here is that we have been given only body tag of html page. So we have to add JavaScript under body tag of the page. One difficulty that I faced was if there is some error in JavaScript, it simply doesn’t execute the script. So using alert to debug into the JavaScript problem is very useful here. You can get the element in JavaScript using document.getElementById(). But it you want to use syntax document.form.element_name then you should use it like document.mturk_form.element_name. This has worked properly in my case. One more precaution while using JavaScript with mTurk form is that mTurk validates html file with stricter validations. So if your JavaScript is working fine in your html editor but not in mTurk, then there could be syntax problem with your JavaScript which is not supported by mTurk due to stricter validation rules. Technorati Tags: Amazon mTurk , JavaScript

ado.net service end point exception

While using ADO.NET Service, we need to be very careful about setting initial Entity reference; otherwise the errors do not reveal cause. E.g. suppose you have not given proper entity reference, the error that it throws while viewing service in browser is Service 'NorthWindDataService' implements multiple ServiceContract types, and no endpoints are defined in the configuration file. WebServiceHost can set up default endpoints, but only if the service implements only a single ServiceContract. Either change the service to only implement a single ServiceContract, or else define endpoints for the service explicitly in the configuration file. So we may look to change settings for service endpoints. But the error is actually because of improper service reference. Technorati Tags: ado.net data service , entity data model