Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Visual Basic/Asp.net Upload

Posted on 2011-03-07
1
Medium Priority
?
273 Views
Last Modified: 2012-06-27
The code attached allows the user to select a .csv document for importing and then lists all records on the form.  I am trying to then import this into table(s) into a  sql.  I have a hosted server so I don't have the ability to use Bulk Insert.  Any other ideas?  Thank you.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        If FileUpload1.HasFile Then
            Try
                Dim fileName As String = System.Guid.NewGuid.ToString + ".tmp"

                FileUpload1.SaveAs("C:\Windows\Temp" & fileName)

                Label1.Text = "File name: " & FileUpload1.PostedFile.FileName & "<br>" & _
                             "Saved name: " & fileName & "<br />" & _
                              "File Size: " & FileUpload1.PostedFile.ContentLength & " kb<br>" & _
                           "Content type: " & FileUpload1.PostedFile.ContentType

                If FileUpload1.PostedFile.ContentLength < 10000 Then
                    Dim objReader As System.IO.StreamReader = New System.IO.StreamReader(FileUpload1.PostedFile.InputStream)
                    Dim data As String = objReader.ReadToEnd

                    Label2.Text = data
                Else
                    Label1.Text = "ERROR: The size of the file you uploaded is grater than 10kb."
                    Label2.Text = ""
                End If

            Catch ex As Exception
                Label1.Text = "ERROR: " & ex.Message.ToString()
                Label2.Text = ""
            End Try
        Else
            Label1.Text = "ERROR: You have not specified a file."
            Label2.Text = ""
        End If
    End Sub
End Class

Open in new window

0
Comment
Question by:rcowen00
1 Comment
 
LVL 9

Accepted Solution

by:
joshbula earned 2000 total points
ID: 35061955
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question