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

Multi-Selecting Files in ASP.NET

Does anyone know of a C#/ASP.NET Open File dialog that I can use in an
aspx page that allows multiselect? I need to be able to select and upload
numerous files.
Is there a reason why MS has made this so difficult? I am willing to pay
for such a control.
Nov 16 '05 #1
4 2663
Chris,

It's not MS that made it so difficult, but the HTML standard that
dictates how file upload controls are supposed to work.

If you want to do this, you will have to dynamically create file input
elements with javascript, and then determine how many elements were sent to
the server (you would name the elements file1, file2, etc, etc, to fileN,
then you would check for the existence of elements 1, 2 .. N).

Either that, or embed a control in the page (ActiveX or .NET) that will
allow you to bring up a dialog that allows you to select multiple files, and
upload all of them (however, you will have to do the same thing, either
upload them in separate requests, or create separate ids for each request).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Chris Jones" <Ch********@discussions.microsoft.com> wrote in message
news:58**********************************@microsof t.com...
Does anyone know of a C#/ASP.NET Open File dialog that I can use in an
aspx page that allows multiselect? I need to be able to select and upload
numerous files.
Is there a reason why MS has made this so difficult? I am willing to pay
for such a control.

Nov 16 '05 #2
Nick,

Are you sure of that JavaScript and if so, can you give than a sample for
me. In my knowledge that is not possible with JavaScript and why Microsoft
should remove those elements from VB script before it was allowed on
Internet..

So when you have that sample, I would be glad to have that (serious).

For the rest I would have written it almost the same with other words of
course.

Cor
Nov 16 '05 #3
Cor,

Here is the code that shows you how to add a new file upload element
dynamically. The important part is near the call to createElement. It
creates the input element, and sets the input type to "file", as well as
setting the name and the id. The rest isn't as important. Basically, it is
embedded in a table that I add new rows to dynamically (with a button
outside the table of course), and I set the id and name according to the
number of rows in the table.

You still have to process the files on the other side. You have to
decide on a name for the input elements, and then check for those elements
(which will have a number appended to them). When the element doesn't
exist, you can stop processing.

Here is the code for the javascript:

//////////////////////////////////////////////////
//
// function AddFileUpload()
//
// Nicholas Paldino 4/26/2002
//
// Adds a new row for a file upload dialog to the page.
//
//////////////////////////////////////////////////
function AddFileUpload()
{
// Get the appropriate table body first.
var pobjTableBody = document.all("filesToUploadBody");

// The id that will be used.
var pintRowNumber = pobjTableBody.rows.length;

// Now create a row.
var pobjNewRow = document.createElement("tr");

// Set the style of the row based on whether or not it is odd or even.
SetRowStyle(pobjNewRow.style, pintRowNumber);

// Create the two columns, the one with the file input and the
// one with the alternate name.
var pobjFileCell = document.createElement("td");
var pobjAlternateFileNameCell = document.createElement("td");

// The file header and the alternate file elements.
var pobjFileHeader = document.all("fileHeader");
var pobjAlternateNameHeader = document.all("alternateNameHeader");

// The table itself.
var pobjTable = document.all("filesToUpload");

// Now create the file element and set the properties.
var pobjFileInput = document.createElement("input");
pobjFileInput.type = "file";
pobjFileInput.id = ("file" + pintRowNumber);
pobjFileInput.name = pobjFileInput.id;
pobjFileInput.style.width = (pobjFileHeader.clientWidth -
(pobjTable.cellPadding * 2)) + "px";

// Now create the alternate file name.
var pobjAlternateFileNameInput = document.createElement("input");
pobjAlternateFileNameInput.type = "text";
pobjAlternateFileNameInput.id = ("alternateName" + pintRowNumber);
pobjAlternateFileNameInput.name = pobjAlternateFileNameInput.id;
pobjAlternateFileNameInput.style.width =
(pobjAlternateNameHeader.clientWidth - (pobjTable.cellPadding * 2)) + "px";

// Add the file input and the filename box to the appropriate cells.
pobjFileCell.appendChild(pobjFileInput);
pobjAlternateFileNameCell.appendChild(pobjAlternat eFileNameInput);

// Add the cells to the row.
pobjNewRow.appendChild(pobjFileCell);
pobjNewRow.appendChild(pobjAlternateFileNameCell);

// Add the row to the body.
pobjTableBody.appendChild(pobjNewRow);

// That's all folks.
return;
}

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Cor Ligthert" <no************@planet.nl> wrote in message
news:O9**************@TK2MSFTNGP10.phx.gbl...
Nick,

Are you sure of that JavaScript and if so, can you give than a sample for
me. In my knowledge that is not possible with JavaScript and why Microsoft
should remove those elements from VB script before it was allowed on
Internet..

So when you have that sample, I would be glad to have that (serious).

For the rest I would have written it almost the same with other words of
course.

Cor

Nov 16 '05 #4
Nick,

Thanks,

I will try it tomorrow.

Cor
Nov 16 '05 #5

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

Similar topics

37
by: ajikoe | last post by:
Hello, Is anyone has experiance in running python code to run multi thread parallel in multi processor. Is it possible ? Can python manage which cpu shoud do every thread? Sincerely Yours,...
4
by: Frank Jona | last post by:
Intellisense with C# and a multi-file assembly is not working. With VB.NET it is working. Is there a fix availible? We're using VisualStudio 2003 Regards Frank
12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
6
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
6
by: Joe | last post by:
I have 2 multi-list boxes, 1 displays course categories based on a table called CATEGORIES. This table has 2 fields CATEGORY_ID, CATEGORY_NAME The other multi-list box displays courses based on...
4
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the...
5
by: dkelly925 | last post by:
Is there a way to add an If Statement to the following code so if data in a field equals "x" it will launch one report and if it equals "y" it would open another report. Anyone know how to modify...
17
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, Wide character and multi-byte character are two popular encoding schemes on Windows. And wide character is using unicode encoding scheme. But each time I feel confused when...
0
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing...
1
by: mknoll217 | last post by:
I am recieving this error from my code: The multi-part identifier "PAR.UniqueID" could not be bound. The multi-part identifier "Salary.UniqueID" could not be bound. The multi-part identifier...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
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.