473,385 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

File Formatting

347 100+
I have the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Function UploadFile(ByVal SavePath As String) As Boolean
  2.         Dim fileWasUploaded As Boolean = False 'indicates whether or not the file was uploaded
  3.  
  4.         'Checking if the file upload control contains a file
  5.         If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLength > 0 Then
  6.             Try
  7.                 'checking if it was .txt file BEFORE UPLOADING IT!
  8.                 'You used to upload it first...but the file could be a virus
  9.                 If File1.FileName = ("doug.csv") = False Then
  10.                     'The file is not the expected type...do not upload it
  11.                     'just post the validation message
  12.                     message.Text = "Sorry, thats not the correct file."
  13.                     message2.Text = "Please locate and upload 'doug.csv'"
  14.                 Else
  15.                     'The file is a .txt file
  16.                     'checking to see if the file exists already
  17.                     'If it does exist Deleting the existing one so that the new one can be created
  18.                     If IO.File.Exists(SavePath) Then
  19.                         IO.File.Delete(SavePath)
  20.                     End If
  21.  
  22.                     'Now upload the file (save it to your server)
  23.                     File1.PostedFile.SaveAs(SavePath)
  24.  
  25.                     'After saving it check to see if it exists
  26.                     If File.Exists(SavePath) Then
  27.                         'Upload was sucessful
  28.                         message.Text = "Thank you for your submission."
  29.                         fileWasUploaded = True
  30.                     Else
  31.                         'the file was not saved
  32.                         message.Text = "Unable to save the file."
  33.                     End If
  34.                 End If
  35.  
  36.             Catch Exc As Exception
  37.                 'We encountered a problem
  38.                 message.Text = "Your file was not in the correct format. Please contact MSB Customer Service at 512-467-5200."
  39.             End Try
  40.         Else
  41.             'No file was selected for uploading
  42.             message.Text = "Please select a file to upload."
  43.         End If
  44.         Return fileWasUploaded
  45.     End Function
  46.  
  47.     Private Sub SaveToDatabase(ByVal SavePath As String)
  48.         Try
  49.             Dim sqlQueryText As String = _
  50.               "BULK INSERT dialerresults " + _
  51.               "FROM '" & SavePath & "' " + _
  52.               "WITH ( FIELDTERMINATOR = ',' , ROWTERMINATOR = '\n' )"
  53.  
  54.  
  55.             ' and bulk import the data:   
  56.             'If ConfigurationManager.ConnectionStrings("Dialerresults") IsNot Nothing Then
  57.             'Dim connection As String = ConfigurationManager.ConnectionStrings("Dialerresults").ConnectionString
  58.             Dim connection As String = "data source=10.2.1.40;initial catalog=IVRDialer;uid=xxxxx;password=xxxxx;"
  59.  
  60.             Using con As New SqlConnection(connection)
  61.                 con.Open()
  62.                 ' execute the bulk import   
  63.                 Using cmd As New SqlCommand(sqlQueryText, con)
  64.  
  65.                     cmd.ExecuteNonQuery()
  66.  
  67.                 End Using
  68.             End Using
  69.  
  70.             'Else
  71.             'message.Text="ConfigurationManager.ConnectionStrings('Dialerresults') is Nothing!"
  72.             'End If
  73.         Catch ex As Exception
  74.             message.Text = "Your file was not in the correct format. Please contact MSB Customer Service at 512-467-5200."
  75.  
  76.         End Try
  77.     End Sub
  78.  
  79. End Class
  80.  
and what I need to do is check for a few variables before the file is uploaded to the server for a bulk insert. What I'm needing to check is that the time/date fields are correct, that the correct number of fields are there (this is being bulk inserted into a database.)

We currently have the database laid out as

ID
PHONE NUMBER
PATIENT NAME
DR NAME
APPOINTMENTDATE
APPOINTMENTTIME
CURRENTDATE
RESULTS

The appointmentdate and time are laid out as
20100601 2:30, 20100601 2:30
as their format. What I need to test against is that all files that are being uploaded to my server meet that format.

Can anyone think of a relatively easy way to check for these things before the bulk insert is done?

Can this be done in the code behind?

Thanks

Doug
Jul 2 '10 #1
0 860

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: scooterm | last post by:
### Question Can anyone name a text editor or XML editor (prefer open source) that can open a simple table XML file in a spreadsheet-type GUI, without adding any extra formatting or junk to the...
6
by: mescaline | last post by:
Hi I have the following doubt about header files -- I have the foll. 3 files in a folder. File 1: one.cpp #include <hel.h> #include <iostream> using namespace std; int main(){ hello();
1
by: Riko Eksteen | last post by:
Hi I'm reading an xml file into an XmlDocument, adding some nodes, and writing it back out. I would like the nodes I add to assume the same level of indeting as the rest of the document. (I load...
2
by: Colleyville Alan | last post by:
I am using Access and have embedded the ActiveX control Formula One that came with Office 2000. (ver 3.04). I have created and formatted a spreadsheet and now I want to copy the info with...
0
by: marfi95 | last post by:
I have an xml file that I want to maintain the whitespace on and spacing between my sections. I have something like this. <!-- Comment lines A --> <!-- Comment lines A --> <A> <B>test</B>...
25
by: mdh | last post by:
Hi Group, Not looking for an answer, but more of an explanation. Thinking back to those heady days when you had the time to do them, may I ask this. Exercise 1-22 asks for a program to "fold"...
8
by: gopal | last post by:
Hi I am trying to write to log file but the formatting of string is not properly aligned in log file result The results looks some thing like this OK move.xml Successful OK ...
10
by: afromanam | last post by:
Regards, Please help What I'm trying to do is this: (and I can't use reports since I must export to Excel) I export some queries to different tabs in an excel workbook I then loop through...
3
by: kavijaya | last post by:
filename to be copied,the source path and destination path are provided as input from .net app.When I copy file using xp_cmdshell copy /y sourcepath destinationpath the file is copied but the...
0
by: puneetmittal33 | last post by:
Hi, I am facing the following issues and hoping that someone out there would have a resolution to the issue: 1) I am currently working on a web application which handles the payroll data for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.