I have a website which allows the user to download the images from it. I used the following code. It download for most of the images but for some it tries to download as a file without extension. So can you please suggest what might be causing this.

// Output standard image
                    DataRow romImage = DAImage.GetImageByID(imageID);
                    System.Drawing.Image image = GetImage(WebConfigurationManager.AppSettings["ImageLibraryPath"] + romImage["RelPath"]);

                    string extension = romImage["RelPath"].ToString().Substring(romImage["RelPath"].ToString().LastIndexOf(".") + 1);

                    Response.AddHeader("Content-Disposition", "attachment; filename=\"" + romImage["Description"].ToString() + "." + extension + "\"");
                    Response.ContentType = "image/" + extension;
                    System.Drawing.Imaging.ImageFormat imgFormat = System.Drawing.Imaging.ImageFormat.Jpeg  ;

                    image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

Thanks for your response. I was looking for this over a day now. The good news is I found the solution. There was no problem in the code. It is problem with how the file is uploaded. It is the description or the filename by which this file is downloaded. If the file name has / because it is a escape sequence it is not downloaded properly. Hence it appeared as if it forgot the extension suddenly in the middle of downloading the file itself.

This question has already been answered. Start a new discussion instead.