Link to home
Start Free TrialLog in
Avatar of misnstt
misnstt

asked on

Multiple File Upload When Adding New User

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

ASKER CERTIFIED SOLUTION
Avatar of rachitkohli
rachitkohli
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of misnstt
misnstt

ASKER

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