Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
i have this master page and a web form with the master page the problem i have is that the code wont run or save into the folder i want it to, so how do i change the code in the vb?
basically i have a javascript which have a input that allow me to upload a file or image, but the problem, it seem like total skip the code inside

XML
<span style ="font-family:Arial">Click to add files</span>&nbsp;&nbsp;
<pre lang="HTML"><span style ="font-family:Arial">Click to add files</span>  

    <br /><br />
    <div id = "FileUploadContainer">
        <!--FileUpload Controls will be added here -->
    </div>
    <br />
    <input id="ButtonAdd" type="button" value="add" onclick = "AddFileUpload()" />
    <asp:Button ID="btnUpload" runat="server" Text="Upload"  />
<asp:Label ID="lbl2" runat="server" ForeColor="Red"></asp:Label>
    <br />

VB
Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
        For i As Integer = 0 To Request.Files.Count - 1
            Dim PostedFile As HttpPostedFile = Request.Files(i)
            If PostedFile.ContentLength > 0 Then
                Dim FileName As String = System.IO.Path.GetFileName(PostedFile.FileName)
                PostedFile.SaveAs(Server.MapPath("Files\img\") + FileName)

            Else
                lbl2.Text = "No images have been selected to upload "
            End If
        Next
    End Sub

JavaScript
<script type = "text/javascript">
       var counter = 0;

       function AddFileUpload() {
           var div = document.createElement('DIV');
           div.innerHTML = '<input id="file' + counter + '" name = "file' + counter + '" type="file" /><input id="Button' + counter + '" type="button" value="Remove" onclick = "RemoveFileUpload(this)" />';
           document.getElementById("FileUploadContainer").appendChild(div);
           counter++;
       }
       function RemoveFileUpload(div) {
           document.getElementById("FileUploadContainer").removeChild(div.parentNode);
       }
       $(document).ready(function () {
           AddFileUpload();
       });

   </script>
Posted
Updated 2-Feb-12 23:53pm
v4

1 solution

I think your 'mappath' needs to start with a / to map to the application root. Beyond that, based on your vague description, I'm not sure what's going wrong or what the problem could be.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900