FileUpload FileSpec

R

Rory Becker

Is there any way to tell the FileUpload control to produce a clientside dialog
with a particular filespec filter on it.

For example I would like to restrict users to only uploading pdf files.

Thanks
 
J

Juan T. Llibre

if (FileUpload1.HasFile)
{
string filename = FileUpload1.FileName;
string extension = System.IO.Path.GetExtension(FileUpload1.FileName);
if (extension == ".pdf")
{
//your upload code...
}
}
 
R

Rory Becker

Hello Juan,
if (FileUpload1.HasFile)
{
string filename = FileUpload1.FileName;
string extension = System.IO.Path.GetExtension(FileUpload1.FileName);
if (extension == ".pdf")
{
//your upload code...
}
}

Thanks Juan. I already have something like that on the server-side.

I was hoping however to present the user of my site with a slightly friendlier
interface by masking out everything other than pdfs in the dialog itself.

Looking around the net it doesn't seem like it's possible though.
 
A

Allen Chen [MSFT]

Hi Rory,

As Patrice said, the accept attribute is not widely supported in current
browsers. You can refer to this article for some workarounds:
http://www.cs.tut.fi/~jkorpela/forms/file.html#filter

I have another suggestion for you, that is using Silverlight, which is a
cross-browser plug-in. We can filter the file in this way:
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Image
Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*";

I suggest you to wait for the release of Silverlight 2. In the mean time
you can learn Silverlight 2 Beta 2 first.
To get started with Silverlight:
http://silverlight.net/GetStarted/

Please feel free to let me know if you have further questions. You can also
ask questions in the Silverlight forum:
http://silverlight.net/forums/

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| Date: Thu, 21 Aug 2008 14:17:47 +0000 (UTC)
| Message-ID: <[email protected]>
| From: Rory Becker <[email protected]>
| Subject: Re: FileUpload FileSpec
| References: <[email protected]>
| MIME-Version: 1.0
| Content-Transfer-Encoding: 8bit
| Content-Type: text/plain; charset=iso-8859-1; format=flowed
| X-Newsreader: JetBrains Omea Pro 1098.1
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: host86-143-211-151.range86-143.btcentralplus.com
86.143.211.151
| Lines: 1
| Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP02.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:74407
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hello Juan,
|
| > if (FileUpload1.HasFile)
| > {
| > string filename = FileUpload1.FileName;
| > string extension = System.IO.Path.GetExtension(FileUpload1.FileName);
| > if (extension == ".pdf")
| > {
| > //your upload code...
| > }
| > }
|
| Thanks Juan. I already have something like that on the server-side.
|
| I was hoping however to present the user of my site with a slightly
friendlier
| interface by masking out everything other than pdfs in the dialog itself.
|
| Looking around the net it doesn't seem like it's possible though.
|
| --
| Rory

|
|
 
A

Allen Chen [MSFT]

Hi Rory,

Is this problem solved? Please feel free to let me know if you need further
assistance.

Regards,
Allen Chen
Microsoft Online Community Support


--------------------
| Date: Thu, 21 Aug 2008 14:17:47 +0000 (UTC)
| Message-ID: <[email protected]>
| From: Rory Becker <[email protected]>
| Subject: Re: FileUpload FileSpec
| References: <[email protected]>
| MIME-Version: 1.0
| Content-Transfer-Encoding: 8bit
| Content-Type: text/plain; charset=iso-8859-1; format=flowed
| X-Newsreader: JetBrains Omea Pro 1098.1
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: host86-143-211-151.range86-143.btcentralplus.com
86.143.211.151
| Lines: 1
| Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP02.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:74407
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hello Juan,
|
| > if (FileUpload1.HasFile)
| > {
| > string filename = FileUpload1.FileName;
| > string extension = System.IO.Path.GetExtension(FileUpload1.FileName);
| > if (extension == ".pdf")
| > {
| > //your upload code...
| > }
| > }
|
| Thanks Juan. I already have something like that on the server-side.
|
| I was hoping however to present the user of my site with a slightly
friendlier
| interface by masking out everything other than pdfs in the dialog itself.
|
| Looking around the net it doesn't seem like it's possible though.
|
| --
| Rory

|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top