Solved

Visual Basic/Asp.net Upload

Posted on 2011-03-07
1
265 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

830 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