0

I'm trying to implement a file upload system and I don't really get what to do.

I'm looking for the easiest way to do it. After long researches, I've found those explanations.

forums.asp.net/t/1678157.aspx/2/10

So, here is the things I've done inside the view :

 @Code
     Dim fileName As String = ""
     If (IsPost) Then
         Dim uploadedFile = Request.Files(0)
         fileName = Path.GetFileName(uploadedFile.FileName)
         fileSavePath = Server.MapPath("~/Content/Uploads/" + fileName)
         uploadedFile.SaveAs(fileSavePath)
     End If
 End Code

 <form action="" method="post">
    @FileUpload.GetHtml(
         initialNumberOfFiles := 1,
         allowMoreFilesToBeAdded := False,
         includeFormTag := True,
         uploadText := "Upload")
 </form>

Problem : GetHtml is not a member of 'System.Web.UI.WebControls.FileUpload' What can I do to fix this? Is it the good way to handle file uploads?

2 Answers 2

1

One problem can be, because you forgot the enctype="multipart/form-data" in your form post.

Then maybe your Upload plugin is not installed correctly. I assume your are using WebMatrix, so this article can be of help

Sign up to request clarification or add additional context in comments.

4 Comments

I'm using VS2010... Does it change smth? There was a plugin to install? I hadn't seen it... That might be the problem I've had the whole day
I never used it, but looking at the turorial it seems that something must be installed (maybe for non VS2010 guys).
I installed this : nuget.org/packages/microsoft-web-helpers but it did not help that much. The error about "@FileUpload.GetHtml" changed. Now, it tells me that FileUpload is not declared and might be not accessible due to protection level.
with the enctype and the correct using it should work. Sorry but I can't be of more help than this
1

Scott Hanselman has a great article on implementing this here

The code is in C# but it should get you started

2 Comments

Thx for this article. It doesn't matter if it's in C#, I'm used to converters now^^
I got a problem with this article. Impossible to convert a 'System.Web.HttpPostedFileBase' into 'System.Web.HttpPostedFile'. I already had this problem with a howto used before.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.