No path is too difficult. No destination is too far !
Development
How to change calendar icon in telerik asp.net control
Mar 14th
It was very hard to find a work around to solve this problem as there was nothing helpful available on internet.
Just use the following line of code inside calendar tag i.e. before this line </radcln:raddatepicker>.
<DatePopupButton ImageUrl=”~/RadControls/Calendar/Skins/myStyle/Img/datePickerPopup.gif” HoverImageUrl=”~/RadControls/Calendar/Skins/myStyle/Img/datePickerPopupHover.gif” />
How to remove dotted line from HTML link, check box and radio buttons
Mar 14th
Please add the following CSS Styles in your default style sheet or add under style tag in head of the page.
input[type="checkbox"]{ outline: none; }
a{text-decoration: none; outline: 0; }
Graceful Degrading to HTML or ASP.Net page
Feb 4th
Have you ever wonder how Microsoft checks if the Silverlight plugin is not unstalled on your your system then the default ASP.Net website should appear otherwise new Silverlight website must be presented ?
here is the trick called Graceful Degrading
In case no Silverlight plugin has been installed on client’s machine, just present asp.net or HTML version of your page in the Silverlight Tag of your ASP.Net host page.
<asp:Silverlight ID=”xamlApp” runat=”server” Source=”~/ClientBin/SLApp.xap”
MinimumVersion=”2.0.31005.0″>
<PluginNotInstalledTemplate>
<div id=”someHTML” >
<!– Some HTML website code or ASP.Net webpage code –>
</div>
</PluginNotInstalledTemplate>
</asp:Silverlight>
How to convert from IEnumerable to EntitySet to get Entity back in action
Nov 27th
One way of achieving is to use what most google search results find on web i.e.
public static EntitySet<T> ToEntitySet<T> (this IEnumerable<T> source) where T : class
{
var es = new EntitySet<T> ();
es.AddRange (source);
return es;
}
Then you could write your query as follows:
var questions = from q in e.Element(“Questions”).Elements(“Question”)
select new Question
{
Text = q.Attribute(“title”).Value,
Point = (decimal) q.Attribute(“point”),
Choices = (
from c in q.Elements(“Choices”).Elements(“Choice”)
select new Choice
{
Text = c.Attribute(“title”).Value,
Correct = (bool) c.Attribute(“isCorrect”)
}
).ToEntitySet();
};
But to achieve this, one may need to add reference to System.Data.Linq and even then there are sometimes when you don’t find the solution, in cases where only one Entity is required.
A very simple and effective trick for a work around of this problem is to use the following :
var FirstQuestion = Questions.Where(q=>q.ID==someIDParameter).ToList().FirstorDefault();
Now use this and do the work peacefully.
How to solve LoadFromRemoteSources error in VS 2010
Oct 20th
I was facing an issue during the migration of my silverlight application to Visual Studio 2010. The issue was something like there are some references into the application from the network shared folder. When compiling the application there was a weird error saying :
The “ValidateXaml” task failed unexpectedly.
System.IO.FileLoadException: Could not load file or assembly ‘file://\\xxxxxxxx\Assemblies\xxxxx.dll’ or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0×80131515)
File name: ‘file://\\xxxxxxxx\Assemblies\xxxxx.dll’ —> System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Microsoft.Silverlight.Build.Tasks.ValidateXaml.XamlValidator.Execute(ITask task)
at Microsoft.Silverlight.Build.Tasks.ValidateXaml.XamlValidator.Execute(ITask task)
at Microsoft.Silverlight.Build.Tasks.ValidateXaml.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult)
Navigating the microsoft link for this problem, it is bit confusing that we have to add the LoadFromRemoteSources switch to some app.config file or web.config file !! So here is the process to accomplish the task and get rid of thsi ridiculous error:-
- Goto this path in your windows explorer :
C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE - Open the devenv.exe.config file in notepad or any editor of your choice.
- Search for this element closing tag in the file:
</runtime> - Before this element closing tag, Copy and paste the below configuration switch
<loadFromRemoteSources enabled=”true“/> - Save and close the config file
- It’s done !!
Web service software factory in visual studio 2010
Sep 3rd
It is very cool to use WSSF modeling edition as it helps applying proper pattern for your architecture. But when you migrate from Visual Studio 2008 to Visual Studio 2010 (ultimate in my case), the very first thing you note is something like this:
VS2010 failed to load the Software service Factory modeling project (.ssfproduct) into the solution !!
This is all because we need to install new and updated version for the factory. But still there is lot to do in order to make it working, as the new VS1010 needs to have the following things:
- Guidance Automation Extensions 2010
- Microsoft Visual Studio 2010 SDK
- Web Service Software Factory 2010
Install in the same order and enjoy the web service software factory : modeling edition without any issues
How to pass InitParameters to Silverlight in HTML object control
Mar 3rd
There are three different ways in which we can pass parameters to Silverlight from the HTML side:
1. Pass parameters using the HTML object control.
This may be the case using pure HTML page to call silverlight control in it or may be the simple ASp.Net page as usual.
<object width=”100%” height=”100%”>
<param name=”source” value=”ClientBin/SomethingFunny.xap” />
<!– you can pass InitParameters to it. Pass anything like EndPointURI, EndPointName or Even StartPage –>
<param name=”InitParameters” value=”startPage=UnRegisteredLandingPage, EndPointURI=http://www.sehajpal.com/testservice.svc” />
</object>
2. Using ASP.Net page to call silverlight control in it, we can easily pass parameters to it in anyway. One of the old tricks is to have an asp-literal control on the HTML side i.e. MarkUp side, and set its text to the desired HTML output fom code behind.
In the markup:
<asp:Literal ID=”litParam” runat=”server” />In the code behind:
this.litParam.Text = String.Format(“<param name=\”ParamInitParameters\” value=\”{0}\” />”, sInitParms);
3. Using asp-silverlight control to host Silverlight application in an ASP.net website as usual. This is pretty neat approach in terms of playing around with parameters and properties of control hosting the Silverlight app.
In the markup:
<asp:Silverlight ID=”SLControl” runat=”server” Width=”100%” Height=”100%” />
In the code behind:
SLControl.InitParameters = “EndPointURI=” + endPointURI + “,EndPointName=commonservice, UserCredentials=” + CredentialString;
Hope it works for you in different scenarios.
Bind with Enum in Silverlight
Feb 23rd
Silverlight doesn’t have any kind of ObjEctDataProvider with it. So the famous example of binding the controls with an ObjectDataProvider doesn’t work with silverlight as it works with WPF
<UserControl.Resources>
<ObjectDataProvider MethodName=“GetValues” ObjectType=”{x:Type sys:Enum}“ x:Key=“AlignmentValues”> <ObjectDataProvider.MethodParameters>
<x:Type TypeName=“HorizontalAlignment” />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
This can be done via code behind in the Silverlight. Just add a reference to the Reflection assembly.
using System.Reflection;
Use this simple function to get IEnumerable collection out of Enum type.
public IEnumerable<Enum> GetEnumValues(Enum enumeration)
{
return from gField in enumeration.GetType().GetFields(BindingFlags.Static | BindingFlags.Public)
select (Enum)gField.GetValue(enumeration);
}
Just bind the results of this function with your control and its done !
ComboFrom.ItemsSource = GetEnumValues(new SehajService.Currency());
Currency amount in words in indian format using T-SQL Stored Procedure
Feb 18th
I know it is not that much crucial but neither easy to get rid of financial application’s requirements as clients demand more and more facilities even they are small in size.
Here is one that kinda SQL Script that every finance domain expert looks for. That is the currency writer in WORDS instead of digits.
CREATE FUNCTION dbo.AMOUNT_IN_WORDS
(
@Amount INT,
@PAISE INT
)
RETURNS int
BEGIN
DECLARE
–Step 1:
–Here we define the temporary tables to hold the WORDs representation of possible digits/amounts
DECLARE @INNTBL_01 TABLE (RECNO INT IDENTITY(1, 1), MTEXT NVARCHAR(50))
DECLARE @INNTBL_02 TABLE (RECNO INT IDENTITY(1, 1), MTEXT NVARCHAR(50))
–Step 2:
–Now add up the salt and pepper onto table i.e. insert the WORDs into it
INSERT INTO @INNTBL_01 SELECT ‘ONE’
INSERT INTO @INNTBL_01 SELECT ‘TWO’
INSERT INTO @INNTBL_01 SELECT ‘THREE’
INSERT INTO @INNTBL_01 SELECT ‘FOUR’
INSERT INTO @INNTBL_01 SELECT ‘FIVE’
INSERT INTO @INNTBL_01 SELECT ‘SIX’
INSERT INTO @INNTBL_01 SELECT ‘SEVEN’
INSERT INTO @INNTBL_01 SELECT ‘EIGHT’
INSERT INTO @INNTBL_01 SELECT ‘NINE’
INSERT INTO @INNTBL_01 SELECT ‘TEN’
INSERT INTO @INNTBL_01 SELECT ‘ELEVEN’
INSERT INTO @INNTBL_01 SELECT ‘TWELVE’
INSERT INTO @INNTBL_01 SELECT ‘THIRTEEN’
INSERT INTO @INNTBL_01 SELECT ‘FOURTEEN’
INSERT INTO @INNTBL_01 SELECT ‘FIFTEEN’
INSERT INTO @INNTBL_01 SELECT ‘SIXTEEN’
INSERT INTO @INNTBL_01 SELECT ‘SEVENTEEN’
INSERT INTO @INNTBL_01 SELECT ‘EIGHTEEN’
INSERT INTO @INNTBL_01 SELECT ‘NINETEEN’
INSERT INTO @INNTBL_01 SELECT ‘TWENTY’–Similary, insert the multiples
INSERT INTO @INNTBL_02 SELECT ‘TEN’
INSERT INTO @INNTBL_02 SELECT ‘TWENTY’
INSERT INTO @INNTBL_02 SELECT ‘THIRTY’
INSERT INTO @INNTBL_02 SELECT ‘FORTY’
INSERT INTO @INNTBL_02 SELECT ‘FIFTY’
INSERT INTO @INNTBL_02 SELECT ‘SIXTY’
INSERT INTO @INNTBL_02 SELECT ‘SEVENTY’
INSERT INTO @INNTBL_02 SELECT ‘EIGHTY’
INSERT INTO @INNTBL_02 SELECT ‘NINETY’
–Step 3:
–Check for the limit of the amount i.e. what is the place value of digits – LACs, Thousands or Hundreds
DECLARE @WORD VARCHAR(300)
SELECT @WORD = ”
DECLARE @M_AMT01 INT, @M_AMT02 INT
IF @AMOUNT < 10000000 AND @AMOUNT >= 100000 BEGIN
SET @M_AMT01 = @AMOUNT
SELECT @AMOUNT = ( @AMOUNT % 100000 )
SET @M_AMT01 = ( @M_AMT01 – @AMOUNT ) / 100000
DECLARE @WORD1 VARCHAR(300)
SET @WORD1 = ”
IF @M_AMT01 < 100 AND @M_AMT01 > 20 BEGIN
SET @M_AMT02 = @M_AMT01
SET @M_AMT01 = ( @M_AMT01 % 10)
SET @M_AMT02 = ( @M_AMT02 – @M_AMT01 ) / 10
SET @WORD1 = ( SELECT @WORD1 + MTEXT FROM @INNTBL_02 WHERE RECNO = @M_AMT02 )
END
IF @M_AMT01 <= 20 AND @M_AMT01 <> 0 BEGIN
SET @WORD1 = ( SELECT @WORD1 + MTEXT FROM @INNTBL_01 WHERE RECNO = @M_AMT01 )
END
SET @WORD = @WORD + @WORD1 + ‘ LAC ‘
END
IF @AMOUNT < 100000 AND @AMOUNT >= 1000 BEGIN
SET @M_AMT01 = @AMOUNT
SET @AMOUNT = ( @AMOUNT % 1000 )
SET @M_AMT01 = ( @M_AMT01 – @AMOUNT ) / 1000
SET @WORD1 = ”
IF @M_AMT01 < 100 AND @M_AMT01 > 20 BEGIN
SET @M_AMT02 = @M_AMT01
SET @M_AMT01 = ( @M_AMT01 % 10 )
SET @M_AMT02 = ( @M_AMT02 – @M_AMT01 ) / 10
SET @WORD1 = ( SELECT @WORD1 + MTEXT + ‘ ‘ FROM @INNTBL_02 WHERE RECNO = @M_AMT02 )
END
IF @M_AMT01 <= 20 AND @M_AMT01 <> 0 BEGIN
SET @WORD1 = ( SELECT @WORD1 + MTEXT +’ ‘ FROM @INNTBL_01 WHERE RECNO = @M_AMT01 )
END
SET @WORD = @WORD + @WORD1 + ‘ THOUSAND ‘
END
IF @AMOUNT < 1000 AND @AMOUNT > = 100 BEGIN
SET @M_AMT01 = @AMOUNT
SET @AMOUNT = ( @AMOUNT % 100 )
SET @M_AMT01 = ( @M_AMT01 – @AMOUNT ) / 100
SET @WORD = ( SELECT @WORD + ‘ ‘ +MTEXT + ‘ HUNDRED ‘ FROM @INNTBL_01 WHERE RECNO = @M_AMT01
)
END
IF @AMOUNT < 100 AND @AMOUNT > 20 BEGIN
SET @M_AMT01 = @AMOUNT
SET @AMOUNT = ( @AMOUNT % 10 )
SET @M_AMT01 = ( @M_AMT01 – @AMOUNT ) / 10
SET @WORD = ( SELECT @WORD + MTEXT + ‘ ‘ FROM @INNTBL_02 WHERE RECNO = @M_AMT01 )
END
IF @AMOUNT <= 20 AND @AMOUNT >= 1 BEGIN
SET @WORD = ( SELECT @WORD + MTEXT +’ ‘ FROM @INNTBL_01 WHERE RECNO = @AMOUNT )
END
–STEP 4:
–Calculate the paise also.
DECLARE @WORDP VARCHAR(300)
SET @WORDP = ”
IF @PAISE <> 0 BEGIN
IF @PAISE < 100 AND @PAISE > 20 BEGIN
DECLARE @PAISE_01 VARCHAR(300)
SET @PAISE_01 = @PAISE
SET @PAISE = ( @PAISE % 10 )
SET @PAISE_01 = ( @PAISE_01 – @PAISE ) / 10
SET @WORDP = ( SELECT @WORDP + MTEXT FROM @INNTBL_02 WHERE RECNO = @PAISE_01 )
END
IF @PAISE <= 20 AND @PAISE >= 1 BEGIN
SET @WORDP = ( SELECT @WORDP + MTEXT FROM @INNTBL_01 WHERE RECNO = @PAISE )
END
SET @WORD = @WORD + ‘AND ‘ + @WORDP + ‘ PAISE’
END
–STEP 5:
–Time to return answer from the function.
RETURN (REPLACE(@WORD, ‘ ‘, ‘ ‘))
–Its done dude. Try by yourself.
END
Now when you need to use this function, simply call it inline to any select statement.
CALLING THE FUNCTION
Select dbo.AMOUNT_IN_WORDS(IM.GRAND_TOTAL, 0) AS words from TBL_INVOICE_MAIN IM
Here, it will convert GRAND_TOTAL field from the table TBL_INVOICE_MAIN.
or more simply,
Select dbo.AMOUNT_IN_WORDS(654321, 0)
Isn’t it simple enough !
Create Word Document with Hyperlinks in it with C# code
Feb 18th
First of all you need to add reference to COM library in project.
Add reference to Microsoft word 11.0 word library under COM reference tab Add this in the code behind “using” section
using Microsoft.Office.Interop.Word;
private void CreateWordDocument()
{
// create annonymous object to be referenced throughout
object oMissingReference = System.Reflection.Missing.Value;
object Visible=true;
// define arbitrary starting point for defining range object.
object oStartRange = 0;
object oEndRange = 0;
// create instance of application class
ApplicationClass WordApp = new ApplicationClass();
// create document instance
Document docObject = WordApp.Documents.Add(ref oMissingReference , ref oMissingReference , ref oMissingReference , ref oMissingReference );
// select a range to add some text/image there
Range rng=docObject.Range(ref oStartRange,ref oMissingReference );
rng.Font.Name=”Arial”;
rng.InsertAfter(”Ashish Sehajpal”);
// create Hyperlink object and assign address, screen tip to it
Object address = @”http://www.sehajpal.com”;
Object screenTip = “Welcome to sehajpal.com”;
// adding Hyperlink to the text “Ashish Sehajpal“
rng.Hyperlinks.Add(rng, ref address, ref oMissingReference , ref screenTip, ref oMissingReference , ref oMissingReference );
// give file name to it so as to save the document
object filename = @”C:\createdbycsharp.doc”;
docObject.SaveAs(ref filename, ref oMissingReference , ref oMissingReference , ref oMissingReference , ref oMissingReference , ref oMissingReference ,ref oMissingReference , ref oMissingReference , ref oMissingReference , ref oMissingReference , ref oMissingReference , ref oMissingReference , ref oMissingReference , ref oMissingReference , ref oMissingReference , ref oMissingReference );
WordApp.Visible=true;
}
