Hello
I know how to upload and save uploaded file on hard disk. I used HttpInputFile and HttpPostedFile classes. And then I saved the HttpPostedFile on hard disk. My requirement is to validate the uploaded files before saving them on hard disk. Using HttpPostedFile.InputStream property I can get the stream. I can read the stream in byte array.
But I want to read the individual field of csv file, validate it and then save it to database. Please suggest how to meet this requirement.
Waiting for suggestions
Thank you.
C_sharpkid
Loading
c_sharpkidPosted Dec 31, 2005, 11:22 AM
Protected
Sub btnUpload_Click(ByVal source As Object, ByVal e As EventArgs) Dim i As Int16Dim
MyFileCollection As HttpFileCollection Dim postedFile As HttpPostedFile TryMyFileCollection = Request.Files
If (MyFileCollection.Count > 0) Then For i = 0 To MyFileCollection.Count - 1postedFile = MyFileCollection(i)
Dim filename As String = Path.GetFileName(postedFile.FileName) Dim contentType As String = postedFile.ContentType Dim contentLength As Integer = postedFile.ContentLength Dim loop1 As Int16 Dim savePath As String = "D:\Program Files\Visual studio projects\" Dim sr As StreamReader = New StreamReader(postedFile.InputStream) Dim input As String While sr.Peek() > -1input = input + sr.ReadLine()
End Whilesr.Close()
message.Text = input
postedFile.SaveAs(savePath & filename) 'message.Text = postedFile.FileName & " uploaded" & _ ' "content type: " & contentType & _ ' "
content length: " & contentLength.ToString() Next End If Catch exc As Exception
message.Text = "Failed uploading file" + exc.Message
End Try End Sub