473,465 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

File not uploading but not getting errors.

347 Contributor
I have a site that I've almost completed and while testing it today noticed that it's not uploading any files or doing the bulk insert in SQL that I need it to. Here is my codebehind:

Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2. Imports System.Data   
  3. Imports System.Data.SqlClient
  4. Partial Class _Default
  5.     Inherits System.Web.UI.Page
  6.     Protected Sub Submit1_Click(ByVal sender As Object, ByVal e As EventArgs)
  7.  
  8.         If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLength > 0 Then
  9.             Dim fn As String = System.IO.Path.GetFileName(File1.PostedFile.FileName)
  10.             Dim SaveLocation As String = Server.MapPath("Data") & "\" & fn
  11.             Try
  12.                 File1.PostedFile.SaveAs(SaveLocation)
  13.                 Response.Write(<center>Thank you for your submission.</center>)
  14.  
  15.                 ' get the file that was submitted and check if it was .txt file   
  16.                 Dim theFile As FileInfo = New FileInfo(SaveLocation)
  17.                 If theFile.Extension <> ".txt" Then
  18.                     Response.Write(<center>Please submit a text file.</center>)
  19.                 End If
  20.  
  21.                 Dim importPath As String = Server.MapPath("Data") & "\upload.txt"
  22.                 If File.Exists(importPath) Then
  23.                     ' do something with existing upload.txt file, maybe archive?   
  24.                 End If
  25.  
  26.                 ' rename the uploaded file to upload.txt for importing   
  27.                 theFile.MoveTo(importPath)
  28.  
  29.                 ' and bulk import the data:   
  30.                 Dim connection As String = ConfigurationManager.ConnectionStrings("Dialerresults").ConnectionString
  31.                 Dim results As New DataTable
  32.  
  33.                 Using con As New SqlConnection(connection)
  34.                     con.Open()
  35.  
  36.                     ' execute the bulk import   
  37.                     Using cmd As SqlCommand = con.CreateCommand
  38.                         cmd.CommandText = "bulk insert dialerresults from '" & importPath & "' " & _
  39.                             " with ( fieldterminator = ',', rowterminator = '\n' )"
  40.                         cmd.ExecuteNonQuery()
  41.                     End Using
  42.                 End Using
  43.  
  44.             Catch Exc As Exception
  45.                 Response.Write("Error: " & Exc.Message)
  46.             End Try
  47.         Else
  48.             Response.Write(<center>Please select a file to upload.</center>)
  49.         End If
  50.  
  51.     End Sub
  52. End Class
Can anyone see why the file is not being uploaded? I'm sure its something simple but I've been working on this for a while and may have missed something. Any assistance would be welcome.

Thank you,

Doug
May 5 '10
54 4157
Frinavale
9,735 Recognized Expert Moderator Expert
Do you have permissions to open the file?
ASP.NET User has to have permissions to that folder.
May 6 '10 #51
dougancil
347 Contributor
that file has an "everyone" permission on it with all values checked. So in short your answer would be yes or do I have to create an asp.net user specifically?
May 6 '10 #52
Frinavale
9,735 Recognized Expert Moderator Expert
Well your code couldn't open the file for some reason so ...
I would be inclined to say that you should specifically set these permissions.
These permissions will depend on the operating system you're using.
I recommend googling this one ;)
May 6 '10 #53
dougancil
347 Contributor
Frinny,

I've looked into this, I have made sure that even the sql server user has rights to that admin rights to this folder. I've read a couple of articles stating that I have to have the UNC path to the saved destination. I've tried that too, any ideas as to what may be causing that error?
May 7 '10 #54
Jerry Winston
145 Recognized Expert New Member
I've tried to catch up with this thread but I still have a few questions.

Does the file actually go to your data folder? The error suggests that the file name/path is incorrect. The file was not found - there was no mention of permissions errors. I suggest removing any old upload.txt files from any/all data folders and trying a clean run. I'll bet the upload.txt file is getting dumped elsewhere hence the file not found error.

Does the server have access to the directory and not just the file?
The server will require permissions on the folder and not the file as the file and associate permissions will be deleted regularly.
Aug 10 '10 #55

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

Similar topics

9
by: R. Rajesh Jeba Anbiah | last post by:
Q: How should I handle file upload? A: File uploading requires HTML form of content type "multipart/form-data". The file content has to be POSTed/submitted via the form and once the file is...
0
by: ¦è»P¦èµ^ | last post by:
Any homepage is for teaching file uploading in JAVA, JSP and TOMCAT, such as JSPSmartUpload? thx very much ~ ªÑ²¼»ù®æ¦³¤É¦³¶^, ¶R½æ­n¯à©Ó¾á­·ÀI ~ ~ Samba, more than a low cost File and...
0
by: praba kar | last post by:
Dear All, I have doubt regarding file uploading. When we upload a file to the remote server we can get file type through file extentions. How we can find out file type if a file doesn't have...
1
by: psb | last post by:
WHO HAS THE BEST COMPONENT FOR FILE UPLOAD? HELP!? has anyone achieved 100% success with HTTP uploading with Mac clients??? I thought the whole <input type="file" .../> was a w3c standard that...
4
by: Mukesh | last post by:
Hi all I am trying to upload and save as a picture to "root/Photos" folder in my web application. I am using this code to perform this task DirectoryInfo strFolder = new...
1
by: ali | last post by:
I am writing a script which uploads file to a specific directory; I am using javascript to handle client side exceptions and php script which actually performs file uploading. Php scripts gets...
7
by: yatin.smile | last post by:
I am a fresher in php and java script. that's wy i join a group for do a discussion on different concepts of php and java scripts. now i m working on file uploading.So i need a discussion on this...
3
ganesanji
by: ganesanji | last post by:
hi all, I have written a php coding for uploading a file to a specific folder or location in server which is a Linux server. I think the coding for file uploaing is correct. But it does not...
0
by: Raj | last post by:
Hello, I am planning to provide the Pause/Resume while uploading files. Our site is using both java applet and activex to do this. The list of selected files will be stored in an encrypted...
5
by: dmj07 | last post by:
Can anybody help me with a simple file uploading and retrieving idea? What I need is a simple system that uploads the files to be stored in a SQL database which are then shown on the front end in...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.