[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Visual Basic/Asp.net Upload

Posted on 2011-03-07
1
Medium Priority
?
272 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 2000 total points
ID: 35061955
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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 shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

650 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