Why we need Windows Communication Foundation?

Challenge:

In earlier days, when i was totally newbie to WCF, I was not clear why we need WCF? one thing I was clear that it has something to do with Web Services. But other than that nothing was much clear.
Then at one fine day, I came across Shivprasad Koirala’s .NET Interview questions book. In which he explained why we need WCF and what is WCF using a fictional story. It is really nicely written and it clears why we need WCF.
Before couple of days, I got good time (as I was on holidays) to convert that story in a comic — To make it more funny (And that’s what philosophy I follow — “Coding should be fun” :-)) and comic blog — a new concept which I always wanted to start!
So, here we go my first comic blog article which explains why we need WCF?

Solution:

  • Long Long time ago there lived a hardworking and a nice architecture.
  • Develop a Booking Engine which books tickets for any flight carriers.
  • The nice and hardworking architecture and his team developed a nice booking engine by which you can book tickets through any of the flight Carriers. The Travel Agent Company was very happy with the architecture and his team Memberโ€™s achievements.

  • As time passed by the travel agent’s business grew in multiples
  • Architecture and his team was very excited and they started to work on this new stuff
  • All franchises run on Windows Platform.
  • Booking engine was located in the main head office and all the franchise should communicate to this booking engine.
  • After months he rolled out his project successfully.

  • Time passed by and because of the good automated booking service more companies wanted to take the franchise from the travel agent. But the big issue was many of the franchise did not have windows operating system. They worked on Linux and other Non-Microsoft operating systems.
  • Due to this limitation travel agent was losing lot of franchise business.
  • Now, booking engine runs on two platforms .NET Remoting (for Windows based clients) and Web Services (for non-windows based clients).

  • Franchise client had to wait to get response and was not able to process the next ticket booking until the first one was served. Travel Agent started receiving huge complaints because of this synchronous processing.
  • Booking engine had the capacity of serving 20 tickets / second but it had now to serve 50 tickets / second.
  • when the travel agent makes a booking it will come and fall in the queue and release the travel agent. Booking engine will always poll for this queue. When the booking engine finishes he will publish the booking results back to the queue. Travel agent client can then come at his leisure and see the results.

  • Everyone in the travel company was really happy and impressed by the architect and his team members
  • Travel Agent then felt a huge necessity of a good security model with the booking engine.

  • Till now the travel agent was booking one ticket at a time. But soon he started getting lot of orders to book group family tickets.
  • Consistency – If fatherโ€™s ticket gets canceled. Kidโ€™s ticket should also be got canceled.


They were working on:

  • .NET
  • .NET Remoting
  • Web Services
  • MSMQ
  • WSE
  • COM+


WCF is a unification of all distributed technologies like:

  • .NET Remoting
  • MSMQ
  • Web Services
  • COM+

Thanks a lot Shivprasad Koirala for writing such a nice story!
Happy Coding! ๐Ÿ™‚

Presentation on coding standards and best programming practices

Challenge:

Luckily, I got sometime to come back on this blog and share something with you!
After getting bit experience, making few mistakes [and obviously learning from them] I thought to write an article on coding standards and best programming practices, I know few of you say there are the lot of articles available on web from big guns on this topic. And I agree with you. But all of them are “document” and I’ve penned down “presentation” which shares the best practices in a lighter way! and obviously “reading document” sounds bit boring and “reading presentation” sounds bit interesting and fun! Thatโ€™s what I think “Coding should be fun!” ๐Ÿ™‚
I had started working on this article, and revised it so many times, got it reviewed from friends, got their feedback and included it in the document. Initially planned to give this presentation to audience in person. But due to one or other reasons this idea didn’t work. PPT was ready and was lying in my folder since so long. Today, I thought that I should share it here. So, It will be available to larger audience.

Solution:

It covers following topics:

  • Naming Conventions and Standards
  • Indentation, spacing and comments
  • Coding Best Practices
  • Database Best Practices
  • ASP.NET Best Practices
  • Exception Handling and Logging
  • Visual Studio IDE Tips and Tricks

You can download it from following links:
C# Coding Standards And Best Programming Practices (PDF)
C# Coding Standards And Best Programming Practices (PPT)
Also you can have a quick look from below and if you find it interesting then only you can download ๐Ÿ™‚
PPT
[scribd id=62747117 key=key-2d4x58u7dizv46r6u1mt mode=list]
PDF
[scribd id=62748045 key=key-9ym8vluqb0fcxwz5ovc mode=slideshow]
Thanks to all of them who provided their invaluable suggestions, feedback, and helped me to proof read this PPT.
Eager to listen your views/suggestions/comments/feedback.
If you really liked it, then please spread it. So, it will be beneficial to everyone!
Happy Coding! ๐Ÿ™‚

Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occured because all pooled connections were in use and max pool size was reached.

Challenge:

Have you seen following error?
timeout-expired-the-timeout-period-elapsed-prior-to-obtaining-a-connection-from-the-pool-this-may-have-occured-because-all-pooled-connections-were-in-use-and-max-pool-size-was-reached
Then this post is to solve it!

Solution:

As per the error your code has not closed the opened SqlConnection properly. For example
SqlConnection conn = new SqlConnection(

myConnectionString);
conn.Open();
doSomething(); /*ย  If some error occurs here — Next line will not get called and it will leave connection open */
conn.Close();
Solution:
1.
SqlConnection conn = new SqlConnection(myConnectionString);
try
{
conn.Open();
doSomething(conn);
}
finally
{
conn.Close();ย ย ย  // This line will get called in any case — success/failure
}
So, open your solution in Visual Studio and search in entire solution for all open connections and for all the code implement above suggested solution.
Just a note : If you have written Data Access layer code in code behind file then you are in trouble here. You have to do changes at N number of places. If you would have created separate Data Access layer (Technically Class Library) and Method to do DB operation then your task would have been easy enough!
2) You can raise the connection pool size in the connection string.ย  For example, you can add “Max Pool Size=100” to your connection string to increase the pool size to 100.
Implement above solutions. You should not see any issues any more.
Good to read :
http://blogs.msdn.com/b/tolong/archive/2006/11/21/max-pool-size-was-reached.aspx
Happy DB Access! ๐Ÿ™‚

ASP.NET Session with proxy server

Challenge:

Y’day I came across with nice issue. Basically there is one Web Application developed using ASP.NET and deployed on IIS Server. Now, this application will be accessed by more than 2-3 people from Local area network. So, far so good.
This application uses Session and here issue comes — For all users across different machines were getting access of different persons session data — which should not be the case. Because as per theory “session” is unique for each user. But my dear friend theory is theory in real life you have to face lots of challenges like this. ๐Ÿ™‚

Solution:

So, I jumped in to this issue and first tried to understand what is going on [The basic stuff — which I always do!].
To quick check the Session ID and other Session related information. I decided to code one page which will print my session info on page and it should show me some direction. I opened my favorite tool — Visual Studio and added one page using single file model — which I can deploy easily on server.
The code looks like below:
<%@ Page Language=”C#” AutoEventWireup=”true” %>
<%@ Import Namespace=”System” %>
<!–DOCTYPE html PUBLIC “/-/W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
xmlns=”http://www.w3.org/1999/xhtml”>
<script language=”C#” runat=”server”>
// new line
private const string breakLine = ”
“;
// Strong Start
private const string strongStart = ““;
// Strong End
private const string strongEnd = “”;
private const string sessionTimeKey = “SessionTime”;
protected void Page_Load(object sender, EventArgs e)
{
// generate string with all required information
StringBuilder sessionInformation = new StringBuilder();
if (Session[sessionTimeKey] == null)
// Current Time
Session[sessionTimeKey] = DateTime.Now;
// IsCookieless
sessionInformation.Append(strongStart);
sessionInformation.Append(“IsCookieless : “);
sessionInformation.Append(strongEnd);
sessionInformation.Append(Session.IsCookieless.ToString());
sessionInformation.Append(breakLine);
// IsNewSession
sessionInformation.Append(strongStart);
sessionInformation.Append(“IsNewSession : “);
sessionInformation.Append(strongEnd);
sessionInformation.Append(Session.IsNewSession.ToString());
sessionInformation.Append(breakLine);
// Session.Keys.Count
sessionInformation.Append(strongStart);
sessionInformation.Append(” Total Keys Count : “);
sessionInformation.Append(strongEnd);
sessionInformation.Append(Session.Keys.Count.ToString());
sessionInformation.Append(breakLine);
// Mode
sessionInformation.Append(strongStart);
sessionInformation.Append(” Session Mode : “);
sessionInformation.Append(strongEnd);
sessionInformation.Append(Session.Mode.ToString());
sessionInformation.Append(breakLine);
// SessionID
sessionInformation.Append(strongStart);
sessionInformation.Append(” SessionID : “);
sessionInformation.Append(strongEnd);
sessionInformation.Append(Session.SessionID);
sessionInformation.Append(breakLine);
// Timeout
sessionInformation.Append(strongStart);
sessionInformation.Append(” Timeout : “);
sessionInformation.Append(strongEnd);
sessionInformation.Append(Session.Timeout.ToString());
sessionInformation.Append(breakLine);
// Session Value
sessionInformation.Append(strongStart);
sessionInformation.Append(” Session Value(DateTime) : “);
sessionInformation.Append(strongEnd);
sessionInformation.Append(Convert.ToString(Session[sessionTimeKey]));
sessionInformation.Append(breakLine);
// SERVER_NAME
sessionInformation.Append(strongStart);
sessionInformation.Append(” SERVER_NAME : “);
sessionInformation.Append(strongEnd);
sessionInformation.Append(Request.ServerVariables[“SERVER_NAME”]);
sessionInformation.Append(breakLine);
// SERVER_PORT
sessionInformation.Append(strongStart);
sessionInformation.Append(” SERVER_PORT : “);
sessionInformation.Append(strongEnd);
sessionInformation.Append(Request.ServerVariables[“SERVER_PORT”]);
sessionInformation.Append(breakLine);
// LOCAL_ADDR
sessionInformation.Append(strongStart);
sessionInformation.Append(” LOCAL_ADDR : “);
sessionInformation.Append(strongEnd);
sessionInformation.Append(Request.ServerVariables[“LOCAL_ADDR”]);
sessionInformation.Append(breakLine);
// REMOTE_ADDR
sessionInformation.Append(strongStart);
sessionInformation.Append(” REMOTE_ADDR : “);
sessionInformation.Append(strongEnd);
sessionInformation.Append(Request.ServerVariables[“REMOTE_ADDR”]);
sessionInformation.Append(breakLine);
// REMOTE_HOST
sessionInformation.Append(strongStart);
sessionInformation.Append(” REMOTE_HOST : “);
sessionInformation.Append(strongEnd);
sessionInformation.Append(Request.ServerVariables[“REMOTE_HOST”]);
sessionInformation.Append(breakLine);
// SERVER_NAME
sessionInformation.Append(strongStart);
sessionInformation.Append(” SERVER_NAME : “);
sessionInformation.Append(strongEnd);
sessionInformation.Append(Request.ServerVariables[“SERVER_NAME”]);
sessionInformation.Append(breakLine);
Response.Write(sessionInformation.ToString());
sessionInformation.Append(breakLine);
Response.Write(“———-SESSION CONTENT——————-“);
Response.Write(breakLine);
foreach (string item in Session.Contents)
{
if (Session[item] != null)
{
Response.Write(string.Format(“Key :{0} – Value : {1}”,
item,Convert.ToString(Session[item])));
Response.Write(breakLine);
}
}
}
protected void btnRefresh_Click(object sender, EventArgs e)
{
Response.Redirect(Request.Url.ToString());
}
</script>
<head runat=”server”>
<title>Session Check Page</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<asp:Button ID=”btnRefresh” runat=”server” Text=”Refresh” OnClick=”btnRefresh_Click” />
</div>
<br />
</form>
</body>
</html>
Basically, this page is my favorite page. Before a year using this page’s code only. I fixed one Live issue [Sticky Session was of on Load balancer on our web farm environment]. If you see the code of page it is quite simple. But very useful!
What I check there is Session ID, LOCAL Address and Session value which I store on page load’s not postback only. And it has one nice button called “Refresh” which redirects on same page.
We deployed this page on Server and started accessing it from different – different machines. And we started clicking on “Refresh” button which shown us few strange thing as below:
1. SessionID was changing on each Refresh button’s click – This should not be the case. Because Session ID will be unique till session expires or user closes the browser.
2. Session’s value was also changing on each refresh.
3. REMOTE_ADDR was coming same on 2-3 machines.
Now, we started removing possibilities one by one.
For issue#1 — We checked Web.Config and found that StateNetworkTimeout property has been assigned, frankly it should not cause an issue. But we thought better to remove it. So, we removed it.
#2 ,#3 – Then we realized that we are using Proxy on our LAN and REMOTE_ADDR’s IP address was IP Address of proxy server.
So, we found that Proxy is causing us an issue. To resolve it we removed proxy server’s setting from Internet explorer’s settings for few machines from which we need to access this application.
Isn’t it simple?
Happy Coding! ๐Ÿ™‚

My Article – Microsoft Certification QuickStart Guide

Challenge:

First of all, apologize for not writing anything since last 3 months, 6 days. The reason behind not writing is that currently I’m focusing on learning,exploring and implementing new CMS named as Sitecore. So, now my challenge area has been changed from pure .NET/ASP.NET to Sitecore CMS . And as per my practice I’m sharing my lessons learnt with the world. But not here it’s on my another blog which is here — http://sitecorebasics.wordpress.com/. So, if you are also using Sitecore or wanted to know about it, please do visit my blog.
Anyways, Let’s come to main point.
After so many questions [In Person, on blog etc.] and motivation from friends. Before so long back I wrote an article on Microsoft Certification.
This article will guide you how to give Microsoft certification exams and it will answer all your questions about Microsoft certification exam.

Solution:

You can download it from here — Microsoft_Certification_QuickStart_Guide. Also you can have a quick look from below and if you find it interesting then only you can download ๐Ÿ™‚
[scribd id=56501296 key=key-ee32lpov9yc9d825wna mode=list]
Eager to listen your views/suggestions/comments/feedback.
Happy Certification!
Worth to read :
http://kiranpatils.wordpress.com/2009/06/27/new-milestone-mcts-web70-528/
http://kiranpatils.wordpress.com/2010/04/26/vs-20082010-certification-path/
http://kiranpatils.wordpress.com/2010/01/01/milestone-mcpd-exam-cleared/
3 months, 6 days

CrickoHolic : Cricket Match Score Updater

Challenge

World cup is on! and If you are a cricket fan then you must be checking score update for each match frequently while working. I also do so [When India is playing!]. But sometime while coding I need to keep my Visual studio instance open and at the same time I also want to check score, for which I used to do ALT + TAB, between my Visual Studio and Firefox.
I was thinking to have some tool, which seats at corner of my desktop and keep me updated on latest score without doing any ALT + TAB. You also think so? Then CrickoHolic is the software for that.

Solution

Basically, CrickoHolic will seat at corner of your desktop and keeps you updated about the latest score. And moreover it will always be on TOP of all windows. So, there is no any chance that any window can overlap it. Sounds interesting? Let’s see more about it.

Main features

  • Always on top of all windows.
  • Seats at right bottom corner of your desktop.
  • Auto updated.
  • Shows Current/Recent and Up Coming matches updates.
  • Minimize button added (Thanks to Devang for the suggestion!)

Screen shots


System requirements

.NET 2.0

How to use?

1. Download CrickoHolic.zip.
2. Extract the zip file, you will find file with name CrickoHolic.exe.
3. To run it, just double-click the .exe.
4. That’s it! Enjoy ๐Ÿ™‚

I would like to hear from you

If your feedback is positive tell to your peers else tell to me at : klpatil@hotmail.com. Feel free to post your suggestions/comments/bugs at provided email id or below in the comments section.

Would like to Download? Click here

Eager to have your feedback!
Sourcecode : Coming Soon…

TimeZone Converter : Converts Datetime with just few clicks!

Challenge

We all geeks mostly work with clients/colleagues who are outside india and follows different timezone than us. Or sometime we have some meeting/event which has timezone different than us. And to do the calculation we have to remember all the timezone differences and do the calculation and have you forgot to check whether the time span falls in Daylight saving time? huh.. sounds more complex right? Even me too that’s was thinking to develop a tool which will do this for you ๐Ÿ™‚ Sounds interesting? then here you go..

Solution

TimeZoneInfo is a class which does everything for you! [It is in .NET Framework 3.5]
Finally, I am glad to share this tool with you. Below are few details of it:

Introduction

TimeZone Converter, helps you to convert provided DateTime from one timezone to another timezone, and keeping Daylight Saving Time in mind!

Main features

  • Source timezone to destination timezone conversion with few clicks!
  • Added Speech support.
  • Scrollbar support added.

Screen shots

System requirements

.NET 3.5 SP1

How to use?

1. Download application from following link.
2. Double click on executable.
3. Provide inputs and click on Convert time OR Press Enter.
5. That’s it! Enjoy ๐Ÿ™‚

I would like to hear from you

If your feedback is positive tell to your peers else tell to me at : klpatil@hotmail.com. Feel free to post your suggestions/comments/bugs at provided email id.

Technical links

TimeZoneInfo : http://msdn.microsoft.com/en-us/library/bb396389.aspx

Would like to Download? Click here

Eager to have your feedback!
[Update : 18/2/2012]Sourcecode : Click here to download sourcecode

Debug Your ASP.NET Application that Hosted on IIS

Challenge:

One of my friend asked me that how we can debug Website which is hosted on IIS? The answer was quite simple and I am using it since so long. But I thought I should document it and that’s why putting the information on this blog. So when you guys need to do this, you can do it!

Solution:

First I thought to write my own article. But suddenly thought some one might have already written on this, and I found following nice article:
http://www.codeproject.com/KB/aspnet/ProcessAttache.aspx#9
Article is so nice — Good Job Blog Author!
Just two things I would like to add to it which is as below:

  1. Shortcut for Attach to process menu is CTRL + ALT + P.
  2. If you are using windows XP then you will not find “w3wp.exe“. You will find “aspnet_wp.exe

If you found this post helpful say thanks to CodeProject article author.
Happy Debugging! ๐Ÿ™‚

The conversion could not be completed because the supplied DateTime did not have the Kind property set correctly. For example, when the Kind property is DateTimeKind.Local, the source time zone must be TimeZoneInfo.Local

Challenge:

I was playing with nice and very useful class TimeZoneInfo in .NET Framework 3.5. Using which we can convert DateTime from SourceTimeZone to DestinationTimeZone by just one line.
[sourcecode language=”csharp”]
<pre>DateTime hwTime = new DateTime(2007, 02, 01, 08, 00, 00);
try
{
TimeZoneInfo hwZone = TimeZoneInfo.FindSystemTimeZoneById("Hawaiian Standard Time");
Console.WriteLine("{0} {1} is {2} local time.",
hwTime,
hwZone.IsDaylightSavingTime(hwTime) ? hwZone.DaylightName : hwZone.StandardName,
TimeZoneInfo.ConvertTime(hwTime, hwZone, TimeZoneInfo.Local));
}
catch (TimeZoneNotFoundException)
{
Console.WriteLine("The registry does not define the Hawaiian Standard Time zone.");
}
catch (InvalidTimeZoneException)
{
Console.WriteLine("Registry data on the Hawaiian STandard Time zone has been corrupted.");
}
</pre>
[/sourcecode]
I was playing more with it and suddenly following error popped up when I selected My Source TimeoZone to “(UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi” and Destination TimeZone to “(UTC) Dublin, Edinburgh, Lisbon, London”
System.ArgumentException was unhandled
Message=“The conversion could not be completed because the supplied DateTime did not have the Kind property set correctly.ย  For example, when the Kind property is DateTimeKind.Local, the source time zone must be TimeZoneInfo.Local.\r\nParameter name: sourceTimeZone”
Source=”System.Core”
ParamName=”sourceTimeZone”
StackTrace:
at System.TimeZoneInfo.ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone, TimeZoneInfoOptions flags)
at System.TimeZoneInfo.ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone)
at TimeZoneCoverter.Form1.button1_Click(Object sender, EventArgs e) in E:\TestHarness\TimeZoneCoverter\TimeZoneCoverter\Form1.cs:line 69
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at TimeZoneCoverter.Program.Main() in E:\TestHarness\TimeZoneCoverter\TimeZoneCoverter\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

Solution:

I’ve faced this problem so long back, When I worked on this class for achieving one functionality. But as I haven’t blogged it [Due to deadlines :(] I can’t recall solution easily. But finally I got the solution and without wasting a minute I wrote it down here. So,ย  If in future you/me face this problem we can kill it quickly. So, here you go:
DateTime dateTimeToConvert = new DateTime(dateTimePicker1.Value.Ticks, DateTimeKind.Unspecified);
As shown in above code we’ve provided DateTimeKind to Unspecified. Earlier it as like this:
DateTime dateTimeToConvert = dateTimePicker1.Value; //Error prone code
HTH!
Happy TimeZoneInfo Coding! ๐Ÿ™‚

SharpZipLib is not working When compression is enabled on IIS

Challenge:

Before so many months back I was facing problem related to SharpZipLib. Basically Using SharpZipLib we were zipping a file at runtime and allowing users to save that zipped file at his/her local machine. It works fine on my local box. But when we roll it out on another IIS server it was not working. [General developers problem :)].
When we delved more in to that, then found that another IIS server has been configured for “HTTP Compression“.

Solution:

Okay, so now we were knowing that Issue is due to IIS Server which has HTTP Compression enabled. Unfortunately we can’t disable it as it will affect the performance. So, now we just have one way to make it working which is through code. We tried lot and finally we found a way to do it, it was just one line change in our Response’s ContentType.
Before we see working code, let’s see the code which was having a problem:
[sourcecode languag=”csharp”]
private void DownloadZip(byte[ bufferzip)
{
// Load Zip file
if (bufferzip != null && bufferzip.Length > 0)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.CacheControl = "public";
HttpContext.Current.Response.ContentType = "application/zip"; //This line was causing a problem!
HttpContext.Current.Response.AddHeader("Content-disposition", "attachment; filename=\"MyFile.zip\"");
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.BinaryWrite(bufferzip);
HttpContext.Current.Response.End();
}
}
[/sourcecode]
Now, it’s time to see a working code!
[sourcecode languag=”csharp”]
private void DownloadZip(byte[ bufferzip)
{
// Load Zip file
if (bufferzip != null && bufferzip.Length > 0)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.CacheControl = "public";
HttpContext.Current.Response.ContentType = "application/octet-stream"; // This is real Hero!
HttpContext.Current.Response.AddHeader("Content-disposition", "attachment; filename=\"MyFile.zip\"");
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.BinaryWrite(bufferzip);
HttpContext.Current.Response.End();
}
}
[/sourcecode]
Now, if you compare the working and non working code you will see the difference. HttpContext.Current.Response.ContentType = “application/zip”; was causing an issue and changing it to HttpContext.Current.Response.ContentType = “application/octet-stream”; solved it!

Reference links:

http://community.sharpdevelop.net/forums/p/10467/28859.aspx#28859
http://www.jlaforums.com/viewtopic.php?t=7295390
http://support.microsoft.com/kb/841120
Happy Coding! ๐Ÿ™‚