troubleshooting Question

Multiple File Upload When Adding New User

Avatar of misnstt
misnstt asked on
ASP.NETVisual Basic.NET
2 Comments1 Solution343 ViewsLast Modified:
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 .
<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" />
            <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)
    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);
        <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
<asp:Content ID="Content5" ContentPlaceHolderID="LeftColumnContent" Runat="Server">
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
        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)
                    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

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros