Carl’s Geek Notes

January 23, 2008

Excellent customer service!

Filed under: Guns, Rants — Carl @ 3:19 pm

I typically shoot at least 250 rounds a week through my Walther P22.  After a while of this level of usage, I was noticing that the slide was having a harder time returning to battery after a shot; there would be a slight gap visible between the opening on the slide and the rear of the bore.  It was easy to handle–eject the magazine slightly, pull the slide (the slide didn’t come forward far enough for the extractor to catch), release, reseat the magazine, resume shooting–but becoming annoying nonetheless.

Last Thursday, I called Walther to order a new recoil spring because I suspected that was the problem.  I got a human on the second or third ring who asked how he could help me.  I replied, “I need to order a new recoil spring for a Walther P22.”  He asked for my name and address, and said, “OK, it’ll be on its way today.”  I received it in yesterday’s mail, with no charge.  How’s that for top-notch service?  Kudos to Walther and Smith & Wesson (who fulfilled the order)!

And it has a pretty nice 7-yard group, too:

January 10, 2008

Saving a (possibly binary) file from a URL in C#

Filed under: C#/.NET, Computers, Programming — Carl @ 1:40 pm

Need a quick way to save a file (.PDF, .JPG, .ZIP, etc.) to disk from a URL?  Try this little bit of code:

public static bool SaveFileFromURL(string url, string destinationFileName, int timeoutInSeconds)
{
    // Create a web request to the URL
    HttpWebRequest MyRequest = (HttpWebRequest)WebRequest.Create(url);
    MyRequest.Timeout = timeoutInSeconds * 1000;
    try
    {
        // Get the web response
        HttpWebResponse MyResponse = (HttpWebResponse)MyRequest.GetResponse();

        // Make sure the response is valid
        if (HttpStatusCode.OK == MyResponse.StatusCode)
        {
            // Open the response stream
            using (Stream MyResponseStream = MyResponse.GetResponseStream())
            {
                // Open the destination file
                using (FileStream MyFileStream = new FileStream(destinationFileName, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    // Create a 4K buffer to chunk the file
                    byte[] MyBuffer = new byte[4096];
                    int BytesRead;
                    // Read the chunk of the web response into the buffer
                    while (0 < (BytesRead = MyResponseStream.Read(MyBuffer, 0, MyBuffer.Length)))
                    {
                        // Write the chunk from the buffer to the file
                        MyFileStream.Write(MyBuffer, 0, BytesRead);
                    }
                }
            }
        }
    }
    catch (Exception err)
    {
        throw new Exception("Error saving file from URL:" + err.Message, err);
    }
    return true;
}

Blog at WordPress.com.