Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FileUpload component does not work

Status
Not open for further replies.

flbos

Programmer
Sep 15, 2005
41
NL
Hi all,

I'm new to ASP and I'm working on a project based on ASP and VB.NET. I want to use the FileUpload component on my website but I am not able to do so. I use Visual studio .NET 2003.

The FileUpload component is not in my list of Web form components (design view). If I switch to html-mode and add the FileUpload component by adding:
"<asp:FileUpload ID="fileUpEx" runat="server"></asp:FileUpload>"

then Visual Studio indicates:
"the active schema does not support the element asp:FileUpload"

when compiling I get a Parser Error on the "<asp:FileUpload ID="fileUpEx" runat="server"></asp:FileUpload>" code line

What is going wrong? Do I need to add a certain reference to be able to use this component? Or is it something else?

Thanks!!
 
Thank you for the fast response! This means that I can't use the FileUpload control at all I guess?

But what would then be the best method to handle a file upload?

Thanks!
 
This means that I can't use the FileUpload control at all I guess?
That is correct.

But what would then be the best method to handle a file upload?
You will have to use a standard HTML element e.g. <input id="File1" type="file" />


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Thanks, I understand that the only alternative would be to use a standard HTML element but my concern is how to handle the file upload after the form is submit.

I need to open the file, read it line by line and based on the information on the file add or edit records in a mysql database. I would prefer to do this from my VB.NET code. But is this possible when I use the standard HTML inut element? How would I approach the uploaded file from VB.net in this scenario?
 
Thanks, I try to use that collection but it does not (yet) work for me. I use this form on my page:

<form id="Form2" method="post" enctype="multipart/form-data">
<INPUT id="Testfile" style="Z-INDEX: 107; LEFT: 344px; WIDTH: 240px; POSITION: absolute; TOP: 104px; HEIGHT: 24px" type="file">
<button type="submit" name="test" value="test" style="Z-INDEX: 108; LEFT: 240px; WIDTH: 96px; POSITION: absolute; TOP: 208px; HEIGHT: 24px">test</button>
</form>

In my VB.NET code I try to catch the uploaded file (and save it to C:\ for this test):

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim f As String
Dim file
For Each f In Request.Files.AllKeys
file = Request.Files(f)
file.SaveAs("c:\" & file.FileName)
Next f
End Sub

But this does not work. I also tried it with adding ' runat="server"' for the the form tag but that also did not work..

Anyone an idea why the above solution (with or without runat="server") doesn't work?
 
Actually, if you are just uploading the one file, an easier method is to add runat="server" to the input tag and then you can just access the object directly e.g.
Code:
<input id="File1" type="file" runat="server" />
Code:
File1.PostedFile.SaveAs(Server.MapPath(File1.PostedFile.FileName))


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
thanks I didn't include runat="server" for the input tag, that was the problem. The shorter way of getting the file is also very nice:)

thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top