1 Replies - 2929 Views - Last Post: 03 February 2012 - 07:29 AM Rate Topic: -----

#1 cutexxbaby  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-June 11

unable to save the image upload?

Posted 03 February 2012 - 04:38 AM

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


        <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>  
    
       
    <span style ="font-family:Arial">Click to add files</span>&nbsp;&nbsp;
            
            <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 />
    
         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
            


Is This A Good Question/Topic? 0
  • +

Replies To: unable to save the image upload?

#2 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6507
  • View blog
  • Posts: 14,379
  • Joined: 02-June 10

Re: unable to save the image upload?

Posted 03 February 2012 - 07:29 AM

Quote

It don't work

It seems like the code is doing xyz


More than just a little vague and like you're not really sure what your own code is truly doing.

cutexxbaby What this shows us is that you aren't familiar with breakpoints and how to debug your own code.Learning to debug one's own code is an essential skill. Sadly, one that apparently no college course teaches. Silly if you ask me.

Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute. Visualizing what your code does will let you see why it behaves the way it does.

It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.

TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Form1 talk to Form2



FAQ (Frequently Asked Questions - Updated Jan 2012

Spoiler

This post has been edited by tlhIn`toq: 03 February 2012 - 07:30 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1