Tuesday, April 7, 2009

Calling Javascript functino from your code behind in ASP.Net

Here is the code by which you can call a javascript function within any where of you C# code.



Page.ClientScript.RegisterStartupScript(Page.GetType(), "YourPrompt",
"<script>alert('Hello');</script>");



Hope it works.

Thanks
/Zaq

Wednesday, March 4, 2009

Zip/Unzip using C#

I have spent few hours over internet to find out a way to create zip file using .net 2.0, C#. My intention was to avoid any third party library or application. I started with System.IO.Compression, but I did not find any resource about creating a zip from a directory with files and subdirectory as well. I got few .net library and I felt few of those are quite familier and using wiedly. But as I have some restriction i can not use those. Finally I got a solutoin to create and extract zip file using Shell32.dll. Here is two functions I wrote.

private static void ZipFile(string sourceFolder, string destinationFile)
{
byte[] emptyzip = new byte[] { 80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

FileStream fs = File.Create(destinationFile);
fs.Write(emptyzip, 0, emptyzip.Length);
fs.Flush();
fs.Close();
fs = null;

//Copy a folder and its contents into the newly created zip file
Shell32.ShellClass sc = new Shell32.ShellClass();
Shell32.Folder SrcFlder = sc.NameSpace(sourceFolder);
Shell32.Folder DestFlder = sc.NameSpace(destinationFile);
Shell32.FolderItems items = SrcFlder.Items();
DestFlder.CopyHere(items, 20);
}


private static string UnzipFile(string inputFileName, string destinationPath)
{
if (!Directory.Exists(destinationPath))
Directory.CreateDirectory(destinationPath);

Shell shell = new ShellClass();
Folder sourceFolder = shell.NameSpace(inputFileName);
Folder destinationFolder = shell.NameSpace(destinationPath);
string outputFileName = sourceFolder.Items().Item(0).Name;
destinationFolder.CopyHere(sourceFolder.Items(), "");
return outputFileName;
}


Here is the code to call those function.

ZipFile(@"D:\SourceFolder", @"D:\MyZip.zip");

UnzipFile(@"D:\MyZip.zip", @"D:\ExtractFolder");

Hope this may help you. Thanks.

How to merge multiple .NET assemblies into a single .NET assembly?

Answer is ILMerge, LMerge is a utility for merging multiple .NET assemblies into a single .NET assembly. It works on executables and DLLs alike and comes with several options for controlling the processing and format of the output. See the accompanying documentation for details.

Monday, January 26, 2009

RegExp for Telephone Number

^[+]?[\d]{1,3}[\-]?(([\d]{8,18})|([(]{1}[\d]{8,18}[)]{1}))

Lets explain this RegExp part by part.

"^[+]?" this part ensures that there will be an optional first character which will be a "+". And if you will start with a digit then it will be fine due to the next part of Expression.

"[\d]{1,3}" this part will ensure that you must enter a number not more than 3 digit and not less than 1 digit.

"[\-]?" this part will ensure that you may enter a "-"after satisfying first two part.

"[\d]{8,18}" this part ensure that you need to enter a number from 8-18 digit.

"[(]{1}[\d]{8,18}[)]{1}" this part will ensure that you will start with a "(" and enter a number between 8 to 18 digits and at the end you will enter a ")".

Now "(([\d]{8,18})|([(]{1}[\d]{8,18}[)]{1}))" this part will ensure to have any one part of these two to be satisfied.

Monday, January 5, 2009

Free eBooks download

http://www.ebooksboard.com/

Event list on XHTML

Event list on XHTML

http://www.w3schools.com/tags/ref_eventattributes.asp

Thursday, January 1, 2009

Link for HTML color code in hex with sample

Link for HTML color code in hex with sample.

http://www.colourlovers.com/blog/2007/06/30/ultimate-html-color-hex-code-list/