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.Po stedFile.Conten tType != "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<StringVali dContentTypes()
{
List<Stringvali dContentTypes = new List<String>();
validContentTyp es.Clear();
validContentTyp es.Add("image/gif");
validContentTyp es.Add("image/jpeg");
validContentTyp es.Add("image/pjpeg");
validContentTyp es.Add("image/png");
return validContentTyp es;
}
2. And then for your .PostedFile.Con tentType:
List<String_con tentTypes = ValidContentTyp es();
if (_contentTypes. Exists(delegate (string t) { return FileUpload1.Pos tedFile.Content Type
== 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.c omwrote in message
news:11******** **************@ n59g2000hsh.goo glegroups.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