Uploading files to server and adding new file to database

Hello guys,

I need to enable client computers to be able to upload pictures to a folder on my server. After doing some search, I managed to get it working. Here's my code:

  <script language="VB" runat="server">

   Sub Upload(Source As Object, e As EventArgs)

    If Not (myFile.PostedFile Is Nothing) Then

     Dim intFileNameLength as Integer
     Dim strFileNamePath as String
     Dim strFileNameOnly as String

     'Logic to find the FileName (excluding the path)
     strFileNamePath = MyFile.PostedFile.FileName
     intFileNameLength = Instr(1, StrReverse(strFileNamePath), "\")
     strFileNameOnly = Mid(strFileNamePath, (Len(strFileNamePath)-intFileNameLength)+2)

     myFile.PostedFile.SaveAs("c:\inetpub\uploads\" & strFileNameOnly)
     lblMsg.Text = "File Upload Success."

     'Dim OleDbConnection2 As New OleDbConnection _
     '("provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Inetpub\wwwroot\company\company.mdb")   
         
     Dim strSQL2 As String = "INSERT INTO picName VALUES ('" + MyFile.PostedFile.FileName + "')"
       
     OleDbConnection2.Open()
     Dim cmd2 As New OleDbCommand(strSQL2, OleDbConnection2)
     cmd.ExecuteNonQuery()
     OleDbConnection2.Close()
     OleDbConnection2.Dispose()

     lb_error.Text = ex.Message

     Response.Redirect("done.aspx")=
    End If
   End Sub
  </script>
 </HEAD>
 <body>
  <h3>File Upload</h3>
  <form enctype="multipart/form-data" runat="server" ID="Form1">
   File: <input id="myFile" type="file" runat="server" NAME="myFile">&nbsp;
   <br>
   <br>
   <input type="button" value="Upload" OnServerClick="upload" runat="server" ID="Button1" NAME="Button1">
   <asp:label id="lblMsg" runat="server" />
  </form>
 </body>


However, the problem now arises that I need to record the addition of every new file to an access database. So, I tried to create OLEDBconnections and commands inside the function. However, it does not seem to recognize OLEDBconnections with this error:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30002: Type 'OleDbCommand' is not defined.

My guess is that, since the functions were not done in the code-behind section but rather at the HTML section, it causes the problem. I cannot simply drag and drop the OLEDBconnections and commands from the designing part of VB.NET since I need the contents of myFile.

So, any ideas? Thanks in advance

0
ASPnewGuy
6/10/2005 6:23:25 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

1 Replies
975 Views

Similar Articles

[PageSpeed] 7
Get it on Google Play
Get it on Apple App Store

You need reference to System.Data.OleDB namespace.
Add "Imports System.Data.OleDB" to your vb source file.
0
PaaB
6/10/2005 9:59:06 AM
Reply:

Similar Artilces:

file uploader save file on server and in database and upload this file on client
hi,i have a file uploader control user can attach files (.rar, .zip, etc) and store file folder and path in database. and another user can click of attach link and can download that file. how can i do this please solve out this problem. you can find your problem solution in this link and you can store the file name in your database server.http://www.aspnettutorials.com/tutorials/network/net-fileupload-aspnet2-csharp.aspxPlease Mark as Answred If This Blog has Helped You.RegardsMitesh Darjihttp://www.indianic.comhttp://www.mitatdotnet.blogspot.com As always there are many ways and which ...

Uploading files to a different file server but not web server
Hi, I want to upload files to a different file server than the web server using asp.net, is that possible?I can use Server.MapPath to store it on the same server. How do I save it to a different machine? What all I need? Do I need IP address? Do I need to have a shared folder on that machine? thank u for the help!!! There is only a few built in ways to get a file from one machine to another in windows.  Things like FTP, HTTP, or File Sharing - you are going to need a path to the server.  You cannot upload directly to that server.  You'll need to upload to your web s...

File Upload to server and save path to uploaded file into a sql database
   I am trying to upload a file to a server and save the path of the uploaded file to a sql 2005 server. I have some code below but im getting the error Object reference not set to an instance of an object. Any help would be greatful. By the way I got this code from these forums and just tweaked them for my website. 1 Dim Fileupload1 As FileUpload = CType(FindControl("FileUpload1"), FileUpload) 2 Dim filePath1 As Label = CType(FindControl("filePath1"), Label) 3 4 If Fileupload1.HasFile Then 5 Try 6 Fileupload1...

File Upload Problem
Hi Everyone,I was grateful to be able to download the code for uploading files into a folder from Sreedhar's web page. The code works well, but whenever there is another new file with the same file name being uploaded into the destination folder, the old file will be replaced. I am wondering if there is any way to solve this problem (How about adding a number to the new file's name, e.g. File1.doc, if there is an existing File.doc?) I am an absolute beginner and any help is deeply appreciated.The original code is as follows: <%@ Page Language="VB" MasterPageFile="~/MasterP...

Is there any correction i have to make to the web.config file connectionstring before uploading to the database files for me to be able to assess my database?
 I just completed asp.net  website created with visual web developer 2005. During development, a database was generated named ASPNETDB.MDF which i took the liberty of adding extra newsletter table.  During development,  clicking the submit button, collect my data and send it to the database, and to view the data collected, i will have to login to view the newsletter administrative page and my web.config  connention string is <connectionStrings>  <add name="ASPNETDBConnectionString1" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilen...

Adding file information to SQL database on file upload
Hi there :) I'm in the final stage of my asp.net project and one of the last things I need to do is add the following file information to my SQL server 2000 database when a file is uploaded: First of all I have a resource table to which I need to add: - filename - file_path - file_size (the resource_id has a auto increment value) so that should hopefully be straight forward when the file is uploaded. The next step is to reference the new resource_id in my module_resource table. My module resource table consists of: - resource_id (foreign key) - module_id (foreign k...

replace existing uploaded file with new file on server
hi,I am working with Asp.net2.0,C#.net. i am uploading resume doc to the server.   requirement is:   eg: i uploaded resume.doc file to the server.(this is done)if i upload another file(newresume.doc) it has to replace the existing file(resume.doc) on the server.and i have to concatinate userid to the filename to differentiate from other userdocument.thenonly there will not be any ambiguity between files if 2 users uploded files with same name.      i am uploading(uploadeddata folder on server) like this.    //button_click  bool fileOK =...

Move File From Web Server to File Server
Our organization has a web server and file server in the same domain. On our public website ordering page, users have the ability to upload a document. The document is currently saved on the Web server in a temp directory. I need to move the uploaded file off the webserver and over to a specific directory on the file server. I have tried using File.Move to accomplish this but encountered permission errors. How does this need to be set up to work? The code format I have is File.Move ("c:\\dir\\file.ext", "\\\\fileserver\\dir\\file.ext"); Thanks in Advance ...

How to File Upload in file server by using web application C#
Currently I am working to upload a csv file  Upload in file server (not on webserver) getting error , I map Y drive to our file server. (y=\\fileserver\load\) Could not find a part of the path 'Y:\LeadsUpload\errorfixsales.xls'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path 'Y:\LeadsUpload\errorfixsales.xls'.   FileUpLoad1...

File Upload on file server not on webserver, by using web application C#
I know how to upload files on webserver, but when trying to upload a file on different machine getting  error I am trying with FileUpLoad1.SaveAs(@"\\enterprise\LeadsUpload" + FileUpLoad1.FileName);getting error Logon failure: unknown user name or bad password.  please help.DostMy website The server services authentication credentials don't have access to your unc path. Why not create a virtual path under you webserver that points to the unc provide the necessary credentials and then write to that path versus the unc path.  Which would also b...

Processes file content before upload (from file upload form)
Hello I have a web aplication that needs to process file content (client side) before uploading them to server. May be I have to use file upload form and somehow read files and sign them on submit event I'm not sure how (and can I) do this in Firefox extension? I prefer to use browser functionality for file upload rather than make my own HTTP connection from my extension. I also prefer not to write any user interface. On 4/7/10 7:27 AM, Юлиян wrote: > I have a web aplication that needs to process file content (client > side) before uploading them to server. htt...

File upload to a server other than the web server.
I have a very simple asp.net upload page. Everything works great when saving the file locally (web server). Things are getting ugly when trying to save files to a different machine (file server, database server,...) So, when using .SaveAs and passing in the UNC path to the new server location I get an *Access denied* error messgae. When mapping a network drive and using the drive letter in the .SaveAs path I get an message saying parts of the path cannot be found. any ideas? thanks  --tolgaApplication Developer Make sure that the account running asp.net web applicaiton(defa...

Importing text file (possibly a excel file) via a web-form to a database.
Hey there - I'm sort of new to this and have a question - which in itself is probably easy, I'm just having trouble finding it. I need to import a text file - possibly later an excel file - into a SQL database via a web-form upload function. Can anyone point me in the right direction? A tutorial page that you know of or sample code, possibly? Any help would be appreciated. Thanks Hi, Take a look @ : - Reading a Delimited File Using ASP.Net and VB.Net - HTHK B ShajudeenAreYaar.comDubai, United Arab Emirates. That was perfect - thank you!...

File upload in chunks
So I downloaded the files from codeproject for the "upload files in chunks" application at http://www.codeproject.com/KB/XML/MTOMWebServices.aspx?df=100&forumid=250646&exp=0&select=2292508 I've adapted the c# code into vb.net and tests I run locally show it working ok.  Trouble is, the client side was written for windows application level client, not web, so I'm wondering if anyone has already got a bit of client side web coding to take an uploaded file and split it into chunks that is compatible with this web service at all? Well I use MTOM and WSE 3.0 ...

Web resources about - Uploading files to server and adding new file to database - asp.net.web-forms

Uploading and downloading - Wikipedia, the free encyclopedia
Examples of a remote system from which a download might be performed include a web server , FTP server, email server, or other similar systems. ...

Facebook Lets You Tag Photos While They're Uploading
Facebook now lets you add tags to photos before they're finished uploading.

Facebook for iPhone 3.0 to Include Video Uploading for 3GS Owners
We’ve heard a lot of people say the iPhone’s built-in support for YouTube video uploading is going to make a huge impact on the number of people ...

Defence bureaucrat pleads guilty to uploading secret document online
... embarrassing security breach with &quot;Five Eyes&quot; intelligence document. A former junior Defence bureaucrat has pleaded guilty to uploading ...

Uploading Bautista bat flip GIFs could get you sued under TPP, copyright activists warn
Copyright activists say Canadians could face lawsuits, fines or worse for ripping the latest Justin Bieber CD or uploading an animated GIF of ...

Xiaomi apologizes for uploading address book data from smartphones without permission
Former Android head and Xiaomi VP Hugo Barra has apologized to owners of its smartphones for "any concern caused" by collecting contact data ...

Senator calls for FTC investigation of Apple and Google over stealth photo uploading capabilities
Is this how we’ll have to open apps in the future? When we broke the news that iOS (and later Android) apps could upload your photo library (along ...

YouTubers Now Uploading Over 35 Hours Of Video Per Minute!
This week YouTube's got some big news! YouTubers are now uploading over 35 hours of video per minute, up from 24 hours a minute in March.

Google Play Books updated with new design, PDF and EPUB uploading
Caught up in all of the hullabaloo around the keynote, Google Play Books received a notable update in the Play Store to not only bring new UI ...

Twitter rolling out group messaging, 30-second video uploading
Fast Company Twitter rolling out group messaging, 30-second video uploading Android Community Different social networks are doing everything ...

Resources last updated: 1/12/2016 5:02:27 AM