When I pass olMHTML it saves it with .msg extension, but if I change the extension to .mht it works as an mht file perfectly and if I don't I have trouble opening the file with .msg extension. If I save it as olMSGUnicode, it saves with no extension but adding the .msg extension makes it work perfectly as a .msg file.
What is the correct way to save as .mht as olMHTML seems to be .msg format although it seems wrong because as I said I have trouble opening the msg file but works fine when renamed to .mht, and olMSGUnicode while doesn't save with an extension by itself, opens file as an .msg file.
To be clear, why is olMHTML saving as msg instead of mht? olMSGUnicode works fine for msg files although they save with no extension adding .msg makes them work perfect. As does changing olMHTML to .mht from .msg.
EDIT: By doing a File.Move() after saving I can rename it to .mht and it works fine, but it would be much more convenient to just save int the correct format.
EDIT2: Code by commenter's request:
if (!filename.EndsWith(".mht"))
{
filename = filename + ".mht";
}
try
{
message.SaveAs(path + filename, Microsoft.Office.Interop.Outlook.OlSaveAsType.olMHTML);
MessageBox.Show(String.Format("Success saving file {0} at {1}", filename, path), "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
string newfilename = filename.Substring(0, filename.Length - 4) + ".mht";
File.Move(path + filename, path + newfilename);
}
catch (System.Exception ex)
{
MessageBox.Show(String.Format("Error {0} while trying to save {1} at {2}", ex, filename, path), "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
I realized I hadn't updated the if statement to not be .msg, it is working now. But still doesn't explain why when using olMHTML as save type, I get a file with no extension rather than with an .mht extension and I have to specify it while with other SaveAs types I do not. But that is a question for another day. I figure the answer out.