A Place for C Sharpers/.Netters

I Will do coding till last moment of life-Kiran Patil

Archive for the ‘Uncategorized’ Category

There is no script engine for file extension “.vbs”

Posted by kiranpatils on August 13, 2009

Challenge:

If you received an error saying There is no script engine for file extension “.vbs” then you are on right post :)

Solution:

I tried doing this : regsvr32 %systemroot%\system32\vbscript.dll

http://www.technologystory.net/2009/02/25/windows-vista-tips-there-is-no-script-engine-for-file-extension-vbs/

But like you — for me too no luck :(

But finally following trick worked for me :)

1. Locate the file %windir%\inf\wsh.inf (inf is a hidden
folder)

2.right click and select “Install”.

Happy Coding!!

Posted in Uncategorized | Leave a Comment »

.NET Framework Common Namespaces and Types Poster

Posted by kiranpatils on May 30, 2009

Background:

This post is dedicated to guys who do believe in OOPS or eager to learn OOPS Concepts[Like me :) ].  Our .NET F/w is built heavily on OOPS concepts. So, if you see take any Class like System.Web.UI.WebControls.TextBox if you see it’s CD and dig more in it you will learn a lot:

image 

This is just one example if you take any Control/Class of .NET F/W you will understand more how it has been designed and why?

So it is always good to have all namespace and types poster with you always too look at it while you are having cup of coffee :)

 Framework Version

Download Link

3.5 http://www.microsoft.com/downloadS/details.aspx?familyid=7B645F3A-6D22-4548-A0D8-C2A27E1917F8&displaylang=en
2.0 http://blogs.msdn.com/photos/brada/images/524537/original.aspx

 

So, Grab this and take a print out of it and have fun :)

Programming With Fun!!

Posted in .NET, Uncategorized | Tagged: , | Leave a Comment »

IE innerHTML – "Unknown runtime error"

Posted by kiranpatils on October 24, 2008

Setting value of <div id=”divhtml”> using js like this :

document.getElementById(“divhtml”).innerHTML = “<form><input type=”text”>…</form>”;

it was giving me error..

Solution:

oldDiv = document.getElementById(divhtml);
newDiv = document.createElement(oldDiv.tagName);
newDiv.id = oldDiv.id;
newDiv.className = oldDiv.className;
newDiv.innerHTML = “<form><input type=”text”>…</form>”;

oldDiv.parentNode.replaceChild(newDiv, oldDiv);

And it worked like a charm!!!!!!

Link : http://piecesofrakesh.blogspot.com/2007/02/ies-unknown-runtime-error-when-using.html

Posted in Uncategorized | Leave a Comment »

Adding application relative path in head section of master Page for JavaScript

Posted by kiranpatils on October 20, 2008

Problem:

I have my application structure similar to as shown below:

image

My JavaScript file has one function which I want to use on each and every page which used my master page. That JS function looks like:


</font>
<font size="2">function HelloWorld()
{
&nbsp;&nbsp;&nbsp; alert("Helloo.....World...");
}</font>
<font size="2">

And to register a JS file i have registered it on one place which is in MASTER..rather than registering it on each and every page. so my master head looks like this:


</font>
<font size="2">
<head runat="server">&nbsp;&nbsp;&nbsp; </font> 

<font size="2"><script language="javascript" type="text/javascript" src="Javascript/HelloWorld.js">
</script>
</head></font>
<font size="2">

on FormWithMasterPage.aspx. i was calling that function as shown below:


</font>
<font size="2"><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
<input type="button" value="OK" onclick="HelloWorld();" />
</asp:Content></font>
<font size="2">

And it was working as expected..means showing alert message:

image

but when i tried the same within SubPageDefault.aspx which is under my SubFolder folder it was throwing an error:

image

Which says that it was unable to find JS function HelloWorld();

In short..How to Add application relative Javascript reference?????

Because for SubPageDefault.aspx function it was trying to find “Javascript/HelloWorld.js” under /SubFolder/javascript/..

Solution:

To solve this problem you need to change bit in your master page head section:

1. Open master page and locate its <HEAD> Section and if it has runat=”server” remove it. [In some case if you are using Themes then it is compulsory to put it..no problem put another head tag with no runat="server".]

2. Hook the code as shown below under <HEAD> for registering JS:


</font>

<font size="2">
<head>&nbsp;&nbsp;&nbsp;
</font><font size="2">
<font color="#0000ff">&nbsp;&nbsp;&nbsp;
<%--To use line as shown below remove runat="server" And if it is required to put runat="server" put one more head with runat="server"--%>
&nbsp;&nbsp;&nbsp;
<script language="javascript" type="text/javascript" src='<%=ResolveClientUrl("~/Javascript/HelloWorld.js")%>'></script></font>
&nbsp;&nbsp;&nbsp; </font>
<font size="2"><font color="#ff0000"><%--Line below will not work--%>
&nbsp;&nbsp;&nbsp;
 <%--<script language="javascript" type="text/javascript" src="Javascript/HelloWorld.js"></script>--%>
</font></head></font>
<font size="2">

That’s it…Happy mastering!!

Source code: http://sites.google.com/site/klpatils/Home/RelativeJSURL.rar?attredirects=0

Links:

http://www.dotnetgenerics.com/Modules/TricksAndTips/ASP.NET/PowerOfTilda.aspx

http://www.odetocode.com/Articles/419.aspx

http://www.odetocode.com/articles/450.aspx – ATOZ of Master Page

Posted in Uncategorized | Leave a Comment »

After building copy Assembly at some specific folder

Posted by kiranpatils on September 18, 2008

Problem:

You have created one Class Library project e.g “BusinessLogic” and other projects are also using it and they are referencing it from C:\MyLibraries folder. Where you put this “Business Logic” Class library. But what happens that you do some changes in your library and forgot to copy it at c:\MyLibraries location. And people starting shout on you…If you are using Visual studio than this thing you can automate using a feature called “Post Build Event”.

Solution

Sounds good idea na….so lets see how can you achieve this step by step:

  1. Right click on your class library and click on properties
  2. It will open up window in left side with list of tabs
  3. Click on “Build Events” Tab.
  4. Here you can see two things:
    1. PreBuild event: comes in action before build.
    2. Postbuild event: comes in action after build.
  5. you can use this DOS Command for achieving the task

COPY Source destination

Click on edit post build event button which will open a window. Here you can see

List of Macros like

TargetDir = your current Class library Bin/debug directory

TargetFileName = your Class library .dll name

And so on which you can explore on your self.

So for copying my .dll to C:\MyLibraries folder I have written like this:

Copy $(TargetDir)\$(TargetFileName) $(TargetDir)\..\..\..\..\ MyLibraries

..\..\..\ = this syntax is for coming up level from child directories. So based on your depth level you can use it wisely.

Posted in Uncategorized | Leave a Comment »

Using showModalDialog() with an ASP.NET page that does PostBack opens another window

Posted by kiranpatils on April 2, 2008

Posted in Uncategorized | Leave a Comment »

Debugging client JavaScript in Visual Studio 2005

Posted by kiranpatils on April 2, 2008

I need to debug JS and i found it from here:

http://geekswithblogs.net/lazydeveloper/archive/2006/07/10/84552.aspx

Thanks to blogging..

Posted in Uncategorized | Leave a Comment »

DateTime formatting with C#.NET

Posted by kiranpatils on March 19, 2008

Whenever you want to format any DateTime in C#.NET and want to return it with specific type then you should use overloaded function of ToString(“<Pattern to get>”).

Some of it is here:

http://www.codeproject.com/KB/cs/DateTime_Patterns.aspx

Enjoy!!

Posted in Uncategorized | Tagged: | Leave a Comment »

How to set a icon for web application?+ASP.NET

Posted by kiranpatils on March 13, 2008

icon.jpg

Have you ever thought that how can i set icon for my Web application developed in ASP.NET. so it can show a custom icon in IE7,Mozilla[as shown above for Google]

Solution:

On any page for which you want to show a custom icon follow the stpes:

1. [One time] put any icon on root of your application folder/at any images folder.

2.add the following tag under <head> tag [i had added on default.aspx]

<link REL=”icon” href=”myicon.ico”/>  //give path of a icon

That’s it

Posted in Uncategorized | Leave a Comment »

Encryption/Decryption Helper Class using RijndaelManaged

Posted by kiranpatils on March 13, 2008

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Cryptography;
namespace RfcDemoPwdGenerator
{
class Helper
{
private static string password = “ABCDE”; //give strong password
private static int iterations = 1024;
private static byte[] salt = Encoding.ASCII.GetBytes(“This is My Salt value”);
/// <summary>
/// this function will take a plaintext as an arg and
/// returns ciphertext as an O/P
/// </summary>
/// <param name=”plaintext”></param>
/// <returns></returns>
public static string Encrypt(string plaintext)
{
Rfc2898DeriveBytes KeyBytes = new Rfc2898DeriveBytes(password, salt, iterations);
//The deafault iteration count is 1000
RijndaelManaged alg = new RijndaelManaged();
alg.Key = KeyBytes.GetBytes(32);
alg.IV = KeyBytes.GetBytes(16);
MemoryStream encryptStream = new MemoryStream();
//Stream to write
CryptoStream encrypt = new CryptoStream(encryptStream, alg.CreateEncryptor(), CryptoStreamMode.Write);
//convert plain text to byte array
byte[] data = Encoding.UTF8.GetBytes(plaintext);
encrypt.Write(data, 0, data.Length); //data to encrypt,start,stop
encrypt.FlushFinalBlock();//Clear buffer
encrypt.Close();
return Convert.ToBase64String(encryptStream.ToArray());//return encrypted data
}

/// <summary>
/// this function will take a ciphertext as an arg and
/// returns plaintext as an O/P
/// </summary>
/// <param name=”plaintext”></param>
/// <returns></returns>
public static string Decrypt(string ciphertext)
{
Rfc2898DeriveBytes KeyBytes = new Rfc2898DeriveBytes(password, salt, iterations);
//The deafault iteration count is 1000
RijndaelManaged alg = new RijndaelManaged();
alg.Key = KeyBytes.GetBytes(32);
alg.IV = KeyBytes.GetBytes(16);
MemoryStream decryptStream = new MemoryStream();
//Stream to read
CryptoStream decrypt = new CryptoStream(decryptStream, alg.CreateDecryptor(), CryptoStreamMode.Write);
//convert  ciphertext to byte array
byte[] data = Convert.FromBase64String(ciphertext); //IF using for WEB APPLICATION and getting ciphertext via Querystring change code to : Convert.FromBase64String(ciphertext.Replace(” “,”+”));

decrypt.Write(data, 0, data.Length); //data to encrypt,start,stop
decrypt.Flush();
decrypt.Close();
return Encoding.UTF8.GetString(decryptStream.ToArray());//return PlainText
}
}
}

Use it and Enjoy!!!!

Posted in Uncategorized | Leave a Comment »