473,387 Members | 1,517 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,387 software developers and data experts.

Upload Files : Set Filter

Hi,

I am using <input type="file"> to upload files in my asp.net application.
I want to set the filter so that user can view only .xls files once he/she clicks the Browse button. Is it possible? How?
--------------------------------
From: vishpala kadam
vi************@yahoo.com

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>y79+Q8elA0OK+IklkT5lHQ==</Id>
Nov 19 '05 #1
3 1974
There is a html attribute where you can specify the filetypes you want to
allow, but the problem is, that most of the browsers (for example IE!)
ignores this attribute.
so you can't really handle this!
You have to check the file on the server after upload.

regards
b.wurm
"vishpala kadam via .NET 247" <an*******@dotnet247.com> schrieb im
Newsbeitrag news:u4**************@TK2MSFTNGP10.phx.gbl...
Hi,

I am using <input type="file"> to upload files in my asp.net application.
I want to set the filter so that user can view only .xls files once he/she
clicks the Browse button. Is it possible? How?
--------------------------------
From: vishpala kadam
vi************@yahoo.com

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>y79+Q8elA0OK+IklkT5lHQ==</Id>

Nov 19 '05 #2
HI vishpala,
you can try with this type of code
OpenFileDialog fileopen = new OpenFileDialog();

fileopen.Title = "Select only Excel File ";

fileopen.Filter = "Excel files(*.xls)|*.xls";

void Browse_Click(object sender, EventArgs e)

{

fileopen.ShowDialog();

}

Alex.

"vishpala kadam via .NET 247" <an*******@dotnet247.com> wrote in message
news:u4**************@TK2MSFTNGP10.phx.gbl...
Hi,

I am using <input type="file"> to upload files in my asp.net application.
I want to set the filter so that user can view only .xls files once he/she
clicks the Browse button. Is it possible? How?
--------------------------------
From: vishpala kadam
vi************@yahoo.com

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>y79+Q8elA0OK+IklkT5lHQ==</Id>

Nov 19 '05 #3
The easiest solution is to allow the user to select what ever file he
wants, but before you actually submit to the server, verify that he has
selected the correct file type. Here is a simple html page that only
allows uploads of certain file types.
<HTML>
<HEAD>
<TITLE>My Upload Page</TITLE></HEAD>
<BODY>
<script language="JavaScript">
function verifyFile()
{
if(document.fileUpForm.uploadedFile.value == "") {
alert("Must choose a file first!");
return false;
}
if(document.fileUpForm.uploadedFile.value.length < 5) {
alert("Invalid filename. Must contain proper extension.");
return false;
}
if(document.fileUpForm.uploadedFile.value.search(
/\.(doc|gif|jpg|jpeg|pdf|txt|xls)$/
) == -1) {
alert("Invalid filename extension.");
return false;
}
return true;
}
</script>
<H2>Upload File</H2>
<form name="fileUpForm" method="POST" enctype="multipart/form-data"
action="http://www.mycomp.com/upload/UploadHandler.aspx"
ID="Form1">
File to upload: <input name="uploadedFile" type="file" size="40"
ID="File1" /><p>
<input type="button" name="submitbutton" value="Submit"
onClick="if(verifyFile()){document.fileUpForm.subm it();}"
ID="Button1" />
</form>
</BODY>
</HTML>

The page only allows uploads of files with the following extension:
doc, gif, jpg, jpeg, pdf, txt, and xls. You can modify the list to
allow your file types.

sayed

Nov 19 '05 #4

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

Similar topics

1
by: Amy Kimber | last post by:
Hello all, ok, I have a file upload secton to my site, two pages, one with a form and one that does the uploading.... some files upload fine, other don't an exe of 300k will upload, but a...
3
by: Brian Birtle | last post by:
**** A CHALLENGE TO THE GURUS - refute the statement "It's impossible to build a file upload progress meter using ASP.NET" **** First person to prove me wrong gets "All Time .NET Programming GOD"...
2
by: Kenneth Myhra | last post by:
Hi all, We are trying to make an ISAPI Filter, in .NET by implementing the IHttpModule interface, that will authorize the request for certain binary file types (GET), this is working fine. But we...
5
by: Neo | last post by:
Hello, I am receiving a file as a binary stream from a C++ Client Application. >From the application, the file is being sent as a "Multipart/form-data". I want to receive this file on the...
3
by: U.C. | last post by:
Hello, My client needs to collect data on a disconnected computer. I am hoping I could store data in Isolated Storage as XML files and expose later to a server (does anyone have experience with...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
18
jhardman
by: jhardman | last post by:
Have you ever wanted to upload files through a form and thought, "I'd really like to use ASP, it surely has that capability, but the tutorial I used to learn ASP didn't mention how to do this."? ...
5
by: camphor | last post by:
hi, I have found an upload script in hotscripts and have implemented it into the website, I followed the installation steps to 'give write permissions to php on the upload folder (which is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.