Closed madu2003 closed 8 years ago
You might be able to map the mime-type of the MimePart image
to a file extension and use that?
e.g.
if (image.ContentType.IsMimeType ("image", "jpeg"))
extensiopn = ".jpg";
else if (image.ContentType.IsMimeType ("image", "gif"))
extension = ".gif";
else if (image.ContentType.IsMimeType ("image", "png"))
extension = ".png";
Thanks for the quick reply.
But where exactly should I place this code?
I believe image.ContentObject.DecodeTo(output); is the code which it writes the file to the disk. But how can I add the extension here?
string SaveImage (MimePart image, string url)
{
string fileName = url.Replace (':', '_').Replace ('\\', '_').Replace ('/', '_');
string path = Path.Combine (tempDir, fileName);
if (!File.Exists (path)) {
using (var output = File.Create (path))
image.ContentObject.DecodeTo(output);
}
return "file://" + path.Replace ('\\', '/');
}
Once you have the extension, add it to the end of fileName
.
fileName += extension;
Hi ,
When there are in-line images in emails I am using the following function to save the images in a folder (HtmlPreviewVisitor class). But the images are saved without a file extension. How can I save with the correct file extension? Thanks.
------------------------------------HtmlPreviewVisitor ---------------------------------------- public class HtmlPreviewVisitor : MimeVisitor { List stack = new List ();
List attachments = new List ();
readonly string tempDir;
string body;