1
Reply

Form validation and naming

Doug Ancil

Doug Ancil

May 4 2010 5:11 PM
2k
have a page that I'm working on that I trying to do the following with:

1. Name a file upload.txt (with codebehind) every time a file is uploaded with a user pressing a submit button.
2. Validate that the file is a .txt file (again with codebehind)
3. Lastly, once the user presses the submit button, that a sql query is run.

I realize that .xml is the proper way to do this but as I'm new to .net, I want to do this with simply inserting the sql query into the codebehind. Here is my codebehind thus far:

 Partial Class _Default
Inherits System.Web.UI.Page


Private Sub Submit1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Submit1.ServerClick

If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLength > 0 Then
Dim fn As String = System.IO.Path.GetFileName(File1.PostedFile.FileName)
Dim SaveLocation As String = Server.MapPath("Data") & "\" & fn
Try
File1.PostedFile.SaveAs(SaveLocation)
Response.Write(<center>Thank you for your submission.</center>)
Dim connection As String = ConfigurationManager.ConnectionStrings("Dialerresults").ConnectionString
Catch Exc As Exception
Response.Write("Error: " & Exc.Message)
End Try
Else
Response.Write(<center>Please select a file to upload.</center>)
End If

End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub
End Class

Here is the sql query that I want to insert into the codebehind above:

bulk insert dialerresults
from '\\MSBWEB3\data\test.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)

Select *
from dialerresults
go

Can any one assist me with this.
Thank you

Doug

I should also mention that the server is running asp.net 3.5 and this is being written in .vb rather than .cs.


Answers (1)
Next Recommended Forum