[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Matching up multiple uploaded files in ASP.NET

Posted on 2013-12-14
5
Medium Priority
?
230 Views
Last Modified: 2013-12-15
So,
I have a form that has multiple uploads.
(lets say an upload for a cake picture and an upload for the recipe)
eg:
<input type="file" name="cakepic" />
<input type="file" name="recipe" />

On the server, i need to put one file in one directory, and one file in another.
The problem I have is, on the server side, how do I tell the two files apart?
(I can't use the FileName as the user can call the files whatever they wish)

How can I get the "name" attribute from Request.Files?
0
Comment
Question by:DFPITC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 21

Accepted Solution

by:
Dale Burrell earned 2000 total points
ID: 39719612
If you are doing something similar to this http://msdn.microsoft.com/en-us/library/system.web.httprequest.files(v=vs.110).aspx

Then the key is the name i.e. "cakepic" or "recipe" - make sense?
0
 
LVL 9

Expert Comment

by:QuinnDex
ID: 39719638
use the extensions to determine if its a pic,

dont allow image extensions in the recipe upload box and only allow certain image extensions in the image upload box ie jpeg, gif, png

you then know what ones are your images and can save them where you like
0
 

Author Comment

by:DFPITC
ID: 39720508
dale_burrell:
That's what i'm trying to do, however, if I loop over AllKeys, it just returns 0s instead of the name.

It is worth noting that the files upload properly, and I can retrieve the filenames properly, just not the "name" attribute on the input.

I can't tell the files apart using the filename as the "cake" analogy isn't the same and they can be files of any type/extension.

--Client--
(this is done for 3 files, put into a "POST" form with "multipart/form-data")
var tObj = document.createElement("input");
tObj.type = "file";
tObj.name = "file1";
tObj.id = "files_file1";
parentDOM.appendChild(tObj);

Open in new window

--Server--
Dim Files As HttpFileCollection = Request.Files
Dim FKeys() As String = Files.AllKeys
Dim k As Integer
For k = 0 To FKeys.GetUpperBound(0)
Response.Write("Key: " & Server.HtmlEncode(FKeys(k)) & VbCrLf)
Next k

Open in new window


I'm expecting this to return:
file1
file2
file3

However, this returns:
0
0
0
0
 
LVL 21

Expert Comment

by:Dale Burrell
ID: 39720532
OK, some things to try.

First asp.net automatically provides a trace utility, which so long as its turned on in web.config will output very useful trace to yoursite.com/trace.axd (http://msdn.microsoft.com/en-us/library/bb386420.aspx).

Looking at the trace will allow you to see what exactly is being posted back to the server.

I have a sneaking suspicion that dynamically adding the input controls directly to the DOM means that asp.net doesn't recognise them even though they should be correctly posted back.

So you could try a test of putting the file input controls in server side just to see if thats part of the issue.

If you set a breakpoint in your code, remembering it needs to be after the Page_Load event (I think) for everything to be loaded correctly. And then inspect the entire Request object, Request.Form, Request.Files etc.

Thats not an answer, but it should provide the information you need to work out what is happening.
0
 

Author Comment

by:DFPITC
ID: 39720591
Ok, so apparently, my issue was that I was using "file" & id rather than "file" + id.

making it a binary compare, rather than a string append.

Doh.

Awarding points to dale as the question was answered, thanks mate :)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question