Sal-
Here's a post that discusses your concern:
http://groups.google.com/group/micro...46302931d090b2
It appears that, since the Browse window is controled by the host OS, that
it's not something you can manipulate (as you could on a WinForms application).
For a workaround, I'd agree with Ben that the content type is probably the
easiest to check since it's a bit more reliable than checking file extensions.
You can do this by accessing the object's ContentType property.
Pseudo-code:
if (FileUpload1.PostedFile.ContentType != "image/jpeg")
{
// logic here
}
If you have a list of valid content types, you can build a list and iterate
through it. For example:
1. Create a generic list of your valid content types.
private static List<StringValidContentTypes()
{
List<StringvalidContentTypes = new List<String>();
validContentTypes.Clear();
validContentTypes.Add("image/gif");
validContentTypes.Add("image/jpeg");
validContentTypes.Add("image/pjpeg");
validContentTypes.Add("image/png");
return validContentTypes;
}
2. And then for your .PostedFile.ContentType:
List<String_contentTypes = ValidContentTypes();
if (_contentTypes.Exists(delegate(string t) { return FileUpload1.PostedFile.ContentType
== t; }))
{
// Logic here
}
HTH.
-dl
---
David R. Longnecker
Web Developer
http://blog.tiredstudent.com
Hi Sal,
I'm actually unaware of a way to do this. The only property of the
file upload control that makes sense would be the Accept property of
the HTML element itself
(http://www.htmlhelp.org/reference/ht...#contenttypes).
Unfortunately I can't seem to get IE to really pay attention to it,
and neither does FF from what I can see.
Perhaps someone else knows....
<ro****@gmail.comwrote in message
news:11**********************@n59g2000hsh.googlegr oups.com...
>I'm using ASP.NET 2.0 and C#. With the FileUpload control is it
possible to set Wildcards (e.g., *.xls and *.doc) so that when the
user clicks the Browse button it defaults to Excel and/or Word files?
Thanks,
Sal