Tuesday, November 21, 2006

In Visual Studio 2005 you may encounter this error when starting an ASP.NET 2.0 debugging session. Particularly you might encounter it if you are using the ASP.NET development server local web server running a local filesystem web site project.

Unable to attach. The binding handle is invalid.

Do you want to continue anyway?

Yes / No

To fix this error, go to Start Menu --> Administrative Tools --> Services

Select the Terminal Services service and make sure it is started.

I got this error because in my machine the Terminal services was disabled.

Thursday, November 16, 2006

huge file transfer over http (asp.net way)

Here is a method which reads the contents of the file in chunks and sends it to the client. this way we avoid unnecessary reading of the full file into the memory

Courtesy: Microsoft website

public void DownloadFile(HttpResponse response, string filepath)
System.IO.Stream iStream = null;

// Buffer to read 10K bytes in chunk:
byte[] buffer = new Byte[10000];

// Length of the file:
int length;

// Total bytes to read:
long dataToRead;

// Identify the file to download including its path.
// string filepath = "DownloadFileName";

// Identify the file name.
string filename = System.IO.Path.GetFileName(filepath);

// Open the file.
iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open,
System.IO.FileAccess.Read, System.IO.FileShare.Read);

// Total bytes to read:
dataToRead = iStream.Length;

response.ContentType = "application/octet-stream";
response.AddHeader("Content-Disposition", "attachment; filename=" + filename);

// Read the bytes.
while (dataToRead > 0)
// Verify that the client is connected.
if (response.IsClientConnected)
// Read the data in buffer.
length = iStream.Read(buffer, 0, 10000);

// Write the data to the current output stream.
response.OutputStream.Write(buffer, 0, length);

// Flush the data to the HTML output.

buffer = new Byte[10000];
dataToRead = dataToRead - length;
//prevent infinite loop if user disconnects
dataToRead = -1;
catch (Exception ex)
// Trap the error, if any.
response.Write("Error : " + ex.Message);
if (iStream != null)
//Close the file.

Other links related to this, may be useful for a reading.