0

Hello,
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.
thanks
Mythili

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

                    Response.Clear();
                    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);
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Mythili.D
0

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.
thanks
Mythili

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.