I have a simple web form that sends and email out via .NET C#. Additionally there is an ASP UPLOAD ctrl from which I create a memory stream and attach the stream to the Mail Message...ie no need to save file to file system.
ISSUE: When MAC users dont inlcude extensions on their uploaded files (I am testing for PostedFile.ContentType to determine the file and/or appropriate extension, allowable files RTF, TXT, PDF, DOC, DOCX) it seems like the ContentType comes back as "application/octet"...this makes some sense to me w/o an extension as required by PCs but; still unclear on weather reading the ContentType or extension is a better way to determine what type of file it is before I attach. [Extensionless MAC file will obviously fail any extension test]
Basically, I read the file from the upload ctrl, determine what its ContentType is, strip just the PostedFile.Filename and then reassemble as I create the attachment using the ContentType string in a switch statement to determine and add the correct extension to the attached file (filename + ext). I did this in order to ensure MAC users that dont use extensions can still upload w/o creating a .ZIP or other package.
Question 1: Is my logic sound with regards to approaching this issue, best practices?
Question 2: Will all MAC files return as "application/octect" when not using an extension on MAC, and if so, how can someone determine what type of file it really is? (Note: PDF worked fine when not using extensions on MAC platform).
Thanks in advance.
If code sample is necessary please advise.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…