How can I vertify the file type and size, I only want it to be a certain type and size. I have read this tutorial on how add the attachments, but now I need to verify it.
1. You said you need the format of file. I will assume that you are needing something like only to add images to attachments. because in other post you have agreed for 4MB file As told by other user like a web.config file setting
CriticalErro...
Member
421 Points
393 Posts
Email attachment, file size and type
Jan 26, 2013 09:33 AM|LINK
How can I vertify the file type and size, I only want it to be a certain type and size. I have read this tutorial on how add the attachments, but now I need to verify it.
http://www.asp.net/web-pages/tutorials/email-and-search/11-adding-email-to-your-web-site
My Site | My Blog
HostingASPNe...
All-Star
15882 Points
2977 Posts
Re: Email attachment, file size and type
Jan 26, 2013 09:55 AM|LINK
Hello,
You could use maxRequestLength and with media type you can control type of attachment. See an example at how to set the maximum size of a file upload in ASP.NET.
Regards
Free ASP.NET Examples and source code.
saeed_saedva...
Member
408 Points
74 Posts
Re: Email attachment, file size and type
Jan 26, 2013 10:25 AM|LINK
into web.config file set it up:
<system.web> <httpRuntime maxRequestLength="102400" executionTimeout="1200" /> </system.web>Saeed Saedvand
CriticalErro...
Member
421 Points
393 Posts
Re: Email attachment, file size and type
Jan 26, 2013 10:30 AM|LINK
Thanks, since the default size is 4MB that is fine for me, do I need to set the file type in web.config?
My Site | My Blog
Afzaal.Ahmad...
Contributor
2662 Points
1040 Posts
Re: Email attachment, file size and type
Jan 26, 2013 12:08 PM|LINK
1. You said you need the format of file. I will assume that you are needing something like only to add images to attachments. because in other post you have agreed for 4MB file As told by other user like a web.config file setting
<system.web> <httpRuntime maxRequestLength="102400" executionTimeout="1200" /> </system.web>I would say that use the <input> element as to only allow the images. Because other files like MP3, MP4 might not be in a range of 4MB
This input field generated will only let the user to select Images nothing else. Than if you want to allow him to add something else use any of these
~~! FIREWALL !~~
CriticalErro...
Member
421 Points
393 Posts
Re: Email attachment, file size and type
Jan 26, 2013 01:27 PM|LINK
The issue with that is, it is client side so the user can change it, the file should still be vertify and server level.
My Site | My Blog
Afzaal.Ahmad...
Contributor
2662 Points
1040 Posts
Re: Email attachment, file size and type
Jan 26, 2013 06:42 PM|LINK
How can user change the input types?
~~! FIREWALL !~~
CriticalErro...
Member
421 Points
393 Posts
Re: Email attachment, file size and type
Jan 26, 2013 06:44 PM|LINK
I am you are assumming HTML <input> ? If so you can change it in the browsers, using developer tools :)
My Site | My Blog
mhcodner
Member
219 Points
86 Posts
Re: Email attachment, file size and type
Jan 27, 2013 05:08 AM|LINK
If you would like to server side validate the filetype this can be achieved by checking the file extension as follows
if (IsPost && Request.Files[0].ContentLength > 0){ if (!Path.GetExtension(Request.Files[0].FileName.ToLower()).Equals(".swf")){ ModelState.AddError("file", "Only Flash files allowed"); } }This example is a snippet from a page on my website which was suggested by Mike Brind.