Using asp:FileUpload I am trying to upload a file to my remote MySql database.(Table Name:files: Field Name filename.) But can’t figure out the correct connection code and how to insert into the below FileUpload code.
My current connect which works with other applications is located in web.config:
<add name="ConnStringName" connectionString="Database=#*$!xx_data;Data Source=xx.#*$!.xx.x;port=#*$!x;UId=#*$!#*$!x;Password=#*$!#*$!;"
providerName="MySql.Data.MySqlClient" />
FileUpload code:
<script type="text/vbscript" runat="server">
Protected Sub Button1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)
If FileUpload1.HasFile Then
Try
FileUpload1.SaveAs("C:\Uploads\" & _
FileUpload1.FileName)
Label1.Text = "File name: " & _
FileUpload1.PostedFile.FileName & "<br>" & _
"File Size: " & _
FileUpload1.PostedFile.ContentLength & " kb<br>" & _
"Content type: " & _
FileUpload1.PostedFile.ContentType
Catch ex As Exception
Label1.Text = "ERROR: " & ex.Message.ToString()
End Try
Else
Label1.Text = "You have not specified a file."
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Upload Files</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" /><br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Upload File" /> <br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label></div>
</form>
</body>
</html>
I am locating the file to be uploaded via the browse button.
Help would be appreciated.
latoc