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);

hi,
y dont u use System.IO.Path.GetExtension
there u can get the extension.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.