I have some shapefiles with extension (.shp) in my pc. But I know that any single shapefile is composed of three mandatory files which are .shp, .shx and .dbf. These files are what makes a shapefile be recognised as shapefile.
I want to write some code in visual studio which enables me to browse computer location and locate such files and then if files are found I want to save them in a SQL Server database.
How can I check if a selected file is truly a shapefile? And what code should I write so as to work with these geography data in SQL Server?
I have heard that SQL Server supports Geography data.
I have created windows form application and a button to browse the file.
Code shown below
Private Sub BtnBrowse_Click(sender As System.Object, e As
System.EventArgs) Handles BtnBrowse.Click
OpenFileDialog1.InitialDirectory = "E:\"
OpenFileDialog1.Filter = "shapefile files (*.shp)|*.|All files
(*.*)|*.*"
OpenFileDialog1.ShowDialog()
txtFileName.Text = OpenFileDialog1.FileName
End Sub
Private Sub BtnSave_Click(sender As System.Object, e As
System.EventArgs) Handles BtnSave.Click
Try
'code to check if it is a shapefile
'code to save shapefile in database
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
I expect that When the BtnSave is clicked the code should check if a file selected is a shapefile, and if true, the files should be saved to sql server else it should throw an exception that the selected file is not a shapefile.