473,405 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

ASP.NET 2.0 FileUpload - Is it possible to set wildcards?

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

Apr 6 '07 #1
4 1951
On Apr 6, 11:27 am, ron...@gmail.com wrote:
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
<asp:FileUpload ID="FileUpload1" runat="server" /><br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Upload File" />&nbsp;<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<asp:RegularExpressionValidator
id="RegularExpressionValidator1" runat="server"
ErrorMessage="Only mp3, m3u or mpeg files are allowed!"
ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))
+(.mp3|.MP3|.mpeg|.MPEG|.m3u|.M3U)$"
ControlToValidate="FileUpload1"></asp:RegularExpressionValidator>
<br />
<asp:RequiredFieldValidator
id="RequiredFieldValidator1" runat="server"
ErrorMessage="This is a required field!"
ControlToValidate="FileUpload1"></asp:RequiredFieldValidator>
Apr 6 '07 #2
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....

--
~~~~~~~~~~~
Ben Rush
http://www.ben-rush.net/blog
<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

Apr 6 '07 #3
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

Apr 6 '07 #4
Thanks for the responses. I didn't think it was possible.

Sal

Apr 9 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Uncle Ben | last post by:
How strong and reliable is the new ASP.NET 2.0 FileUpload control? By that, I mean is it reliable enough to accept 2-gigabyte file uploads per upload session? Also, is it possible or easy to...
0
by: Chris | last post by:
I want to display a formview based on an objectdatasource. One of the things on the formview will be a link to a pdf. When I go into the edit template I would like a fileupload to display, which...
1
by: Marko Vuksanovic | last post by:
I am trying to implement an upload progress indicator using atlas, using the following workaround: http://forums.asp.net/thread/1321664.aspx This is the code in FileUpload.apsx file is as...
3
by: yeltsin27 | last post by:
Theming seems only to affect the text box of a FileUpload control, not the Browse button. Is there any way to theme the button as well? Thanks, ChrisN
0
by: Christian Schlemmer | last post by:
If my code will run into the filesize-limit condition, the INSERT-statement will be executed. is there a way to avoid that? Protected Sub DetailsView1_RowInserting(ByVal sender As Object,...
4
by: Dave | last post by:
Is it possible to change the default location for the FileUpload control so that it searches a file from within the web page file structure? Even more specific...limit it to one folder within that...
3
by: forumaic | last post by:
Hello, I am newbie in this stuff, can somebody to help me. Maybe can somebody to say how to manually to set file name and path in code for fileupload control, not to let to choose file for...
9
by: vital | last post by:
Hi, I have a User control which has a fileupload control. With the requirements I placed the user control in a UpdatePanel of ASP.NET Ajax and the fileupload.postedfile.filename giving error. ...
1
by: bogdan | last post by:
Hi, I have a FormView where one of the items is a file name. All items come from a single data source. I'd like to have the file name also displayed in a FileUpload control on the same page. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.