Solved

Visual Basic/Asp.net Upload

Posted on 2011-03-07
1
266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 9

Accepted Solution

by:
joshbula earned 500 total points
ID: 35061955
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

732 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