Solved

Visual Basic/Asp.net Upload

Posted on 2011-03-07
1
262 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 500 total points
ID: 35061955
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now