473,811 Members | 3,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1973
On Apr 6, 11:27 am, ron...@gmail.co m 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:FileUplo ad ID="FileUpload1 " runat="server" /><br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button 1_Click"
Text="Upload File" />&nbsp;<br />
<br />
<asp:Label ID="Label1" runat="server"> </asp:Label>
<asp:RegularExp ressionValidato r
id="RegularExpr essionValidator 1" runat="server"
ErrorMessage="O nly mp3, m3u or mpeg files are allowed!"
ValidationExpre ssion="^(([a-zA-Z]:)|(\\{2}\w+)\$ ?)(\\(\w[\w].*))
+(.mp3|.MP3|.mp eg|.MPEG|.m3u|. M3U)$"
ControlToValida te="FileUpload1 "></asp:RegularExpr essionValidator >
<br />
<asp:RequiredFi eldValidator
id="RequiredFie ldValidator1" runat="server"
ErrorMessage="T his is a required field!"
ControlToValida te="FileUpload1 "></asp:RequiredFie ldValidator>
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.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

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.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

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
1847
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 implement an upload progress bar using this FileUpload control? Thanks.
0
1107
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 can be used to upload a new pdf. I would like my object to be as reusable as possible. Can anyone recommend a way of referencing the fileupload control in as flexible way as possible. The thing I would like to avoid is using my object on several...
1
7044
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 follows: <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title> drag </title> </head> <body> <form id="f1" enctype="multipart/form-data" runat="server">
3
9616
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
1347
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, ByVal e As DetailsViewInsertEventArgs) Dim FileUpload As FileUpload = DetailsView1.FindControl("Bild")
4
7207
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 web structure?
3
4744
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 user with browse button. For example (textBox) textBox.Text = xxx; textBox.Enable = false; But how to do the same whith file upload?
9
9744
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. I read some articles that Ajax is not compatible with fileupload. I want to know the solution or workaround for this. Thanks
1
1367
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. Ideally I'd like to have the FileUpload control embedded in a FormView so the file name appears only once on the page. Is this possible? What are the alternatives? Thanks, Bogdan
0
9726
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10647
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10130
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7667
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5553
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4338
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.