We help IT Professionals succeed at work.

Multiple File Upload When Adding New User

misnstt
misnstt asked
on
340 Views
Last Modified: 2010-04-14
I have a ASP.NET page with a Create New User Wizard.    Step 3 of the wizard I have some File upload fields and a upload button which successfully uploads the files into a "Upload" folder on the Hard Drive.   Also included in step 3 of the wizard is the Finish button which adds the new user information into  the table.

I need to make adjustments and am unsure how to proceed.  I  want that when the new user presses the upload button  or the Finish button a folder is created in a Upload folder within the root of the site. I want the folder name to be  ased upon the new user "USER NAME".   The new folder should contain the uploaded file for that user.  

I am attaching the code .
Thanks
NEW USER WIZARD PAGE
<asp:WizardStep ID="CreateUserWizardStep2" runat="server" 
            Title="Upload Pictures">
            <input id="File1" runat="server" size="60" type="file"/>
            <br />
            <p id="upload-area">
   <input id="File2" type="file" runat="server" size="60" />
</p>
            <input id="AddFile" onclick="addFileUploadBox()" type="button" 
                value="Add file" /><br />
            <br />
            <asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" 
                Text="Upload Now" />
                <span id="Span1" runat="server" />
                <script type="text/javascript">
function addFileUploadBox()
{
    if (!document.getElementById || !document.createElement)
        return false;
		
    var uploadArea = document.getElementById ("upload-area");
	
    if (!uploadArea)
        return;
 
    var newLine = document.createElement ("br");
    uploadArea.appendChild (newLine);
	
    var newUploadBox = document.createElement ("input");
	
    // Set up the new input for file uploads
    newUploadBox.type = "file";
    newUploadBox.size = "60";
	
    // The new box needs a name and an ID
    if (!addFileUploadBox.lastAssignedId)
        addFileUploadBox.lastAssignedId = 100;
	    
    newUploadBox.setAttribute ("id", "dynamic" + addFileUploadBox.lastAssignedId);
    newUploadBox.setAttribute ("name", "dynamic:" + addFileUploadBox.lastAssignedId);
    uploadArea.appendChild (newUploadBox);
    addFileUploadBox.lastAssignedId++;
}
</script>
        </asp:WizardStep>
        <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
        </asp:CompleteWizardStep>
    </WizardSteps>
</asp:CreateUserWizard>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="LeftColumnContent" Runat="Server">
</asp:Content>
 
    
ASPX.VB Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim UpPath As String
        Dim UpName As String
        UpPath = "C:\UploadedUserFiles"
        UpName = Dir(UpPath, vbDirectory)
        If UpName = "" Then
            MkDir("C:\UploadedUserFiles\")
        End If
    End Sub
 
    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim uploads As HttpFileCollection
        uploads = HttpContext.Current.Request.Files
 
        For i As Integer = 0 To (uploads.Count - 1)
 
            If (uploads(i).ContentLength > 0) Then
                Dim c As String = System.IO.Path.GetFileName(uploads(i).FileName)
 
                Try
                    uploads(i).SaveAs("C:\UploadedUserFiles\" + c)
                    Span1.InnerHtml = "File Uploaded Sucessfully."
                Catch Exp As Exception
                    Span1.InnerHtml = "Some Error occured."
                End Try
 
            End If
 
        Next i
 
    End Sub
End Class

Open in new window

Comment
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks for the help.  I saw the link however it is very vague.  I am very new much a beginner  and I dont know how to wrtie the required code.  If you can outline exactly the code changes I need to make that would be great.  Thanks

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.