I am programming a Website Note -Not A Project in VB in Visual Studio 2010 and have a LINQ database tied in. I have a user registration page built that prompts the user for their name, email, password and the admin level they will require. The is also a function to add a photo. This is implemented via a standard asp:fileupload control. Currently it is not working. I would like for the file to be browsed for, and then all user details added to the database on the click of the "register" button. The code i have so far is below.
Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If IsPostBack Then
        Dim UpPath As String
        UpPath = "~/Uploads/"
        Image1.Visible = True
        Image1.ImageUrl = Session("ImagePath")
        If Not Directory.Exists(UpPath) Then
            Directory.CreateDirectory("C:\UploadedUserFiles\")
        End If
    End If
End Sub
Protected Sub btnRegister_Click(sender As Object, e As System.EventArgs) Handles btnRegister.Click
    Dim savePath = "\Uploads\"
    Dim appPath As String = Server.MapPath("~")
    If (FileUPload1.HasFile) Then
        Dim savePath2 As String = savePath & Session("currentuser") & "" & FileUPload1.FileName
        FileUPload1.SaveAs(appPath & savePath2)
        Session("ImagePath") = "." & savePath
    End If
    ' variables to store the user's registration details
    Dim username As String
    Dim email As String
    Dim password As String
    Dim retypedPassword As String
    ' variables to store the user's selected roles
    Dim productOwner As Boolean
    Dim projectManager As Boolean
    Dim scrumMaster As Boolean
    Dim developer As Boolean
    ' populate variables with the values from the web page
    username = txtUsername.Text
    email = txtEmail.Text
    password = txtPassword.Text
    retypedPassword = txtRetypePassword.Text
    ' check which user roles have been selected
    productOwner = checkProductOwner.Checked
    projectManager = checkProjectManager.Checked
    scrumMaster = checkScrumMaster.Checked
    developer = checkDeveloper.Checked
    ' boolean to check if the entered details are valid
    Dim isValid As Boolean
    isValid = True
    ' check if the values entered by the user are valid
    If _
        String.IsNullOrEmpty(username) Or _
        String.IsNullOrEmpty(email) Or _
        String.IsNullOrEmpty(password) Or _
        String.IsNullOrEmpty(retypedPassword) Or _
        password <> retypedPassword Then
        isValid = False
    End If
    ' if the values are valid, then populate the USER table with the new user and the USER ROLES table
    ' with the roles they are allowed in any project that will be created
    If isValid Then
        ' set up LINQ connection with database
        Dim db As New AgileClassesDataContext()
        ' create a user to populate a row in the USER table
        Dim user As New User With _
        {.Name = username, _
         .Password = password, _
         .Email = email}
        ' add the new user to the USER table
        db.Users.InsertOnSubmit(user)
        ' submit the changes to the database
        Try
            db.SubmitChanges()
        Catch ex As Exception
            Console.WriteLine(ex)
            db.SubmitChanges()
        End Try
Currently I have not declared 'FileUPload1' in the database because whenever i try to add it i get an error saying "Cannot converet type System.Web.UI.WebControls.FileUpload to System.Data.Linq.Binary" I don't know what to do to avoid this. The database table I am using is:
User
-UserID (int, incrementing) -Name (nvarchar) -Password (nvarchar) -Email (nvarchar) -PhotoID (image)
Any suggestions would be great. Thanks
 
     
    