![]() |
Locate File Diologe
HI and TIA! What I'm trying to do is have my user click a button which
opens the find file dialogue box. Once they find it I want to place the full path into a variable so that I can use it as the Source in my connection string. I've tried the HTML File Field control which allows me to navigate to the .mdb file and it places it into the File Field control on my page, however every attempt I try to place it in a variable gives me an error stating that the Page can't be located. I want something like so: Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim con As OleDbConnection Dim strFile As HttpPostedFile strFile = inpFileField.PostedFile con = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA Source=strFile") con.Open() End Sub Any help is appreciated. Thanks for your time! -- Reggie |
Re: Locate File Diologe
Reggie:
A couple thing. The MDB file would be on the client's machine, so you'd want them to upload the file to the server, save it on the server and then use the saved path to which you'll open a connection, right? For example, if I'm on your site and point to an mdb file on my computer, you won't be able to access the file as c:\karl\myfile.mdb. You'll need to save the file on your server and access it there. I say this because that doesn't seem to be what you are doing.... secondly, if you have <input type="file" runat="server" strFile" /> in your page, you should declare protected strFile as HttpPostFile in your class. Not in the function, and it must be protected. Here's a function which makes more sense to me...haven't tried it, just giving you some ideas: in yoru aspx: <input type="file" runat="server" id="file" /> in your codebehind: public class XXX inherits page protected file as HttpPostFile Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click if file.PostedFile.ContentLength > 0 then dim path as string = "c:\myserver\someRepository\" + System.IO.Path.GetFileName(file.PostedFile.FileNam e) file.PostedFile.SaveAs(path) dim connectionString as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" "& path 'rest of the connection stuff here end if end sub hope that helps, Karl -- MY ASP.Net tutorials http://www.openmymind.net/ - New and Improved (yes, the popup is annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to come!) "Reggie" <NoSpam_chief123101@NoSpam_yahoo.com> wrote in message news:jIydneXcYcBdOy_fRVn-2g@comcast.com... > HI and TIA! What I'm trying to do is have my user click a button which > opens the find file dialogue box. Once they find it I want to place the > full path into a variable so that I can use it as the Source in my > connection string. I've tried the HTML File Field control which allows me > to navigate to the .mdb file and it places it into the File Field control > on my page, however every attempt I try to place it in a variable gives me > an error stating that the Page can't be located. I want something like > so: > > > Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > > Dim con As OleDbConnection > > Dim strFile As HttpPostedFile > > strFile = inpFileField.PostedFile > > con = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA > Source=strFile") > > con.Open() > > End Sub > > Any help is appreciated. Thanks for your time! > -- > > Reggie > |
Re: Locate File Diologe
Karl, Exactly what I'm looking for. Knew what I wanted to do just didn't
know how to go about getting it done. Thanks very much for you time. -- Reggie "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:eGg6D0ycFHA.1448@TK2MSFTNGP14.phx.gbl... > Reggie: > A couple thing. The MDB file would be on the client's machine, so you'd > want them to upload the file to the server, save it on the server and then > use the saved path to which you'll open a connection, right? For example, > if I'm on your site and point to an mdb file on my computer, you won't be > able to access the file as c:\karl\myfile.mdb. You'll need to save the > file on your server and access it there. I say this because that doesn't > seem to be what you are doing.... > > secondly, if you have <input type="file" runat="server" strFile" /> in > your page, you should declare protected strFile as HttpPostFile in your > class. Not in the function, and it must be protected. > > Here's a function which makes more sense to me...haven't tried it, just > giving you some ideas: > > in yoru aspx: > <input type="file" runat="server" id="file" /> > > in your codebehind: > > public class XXX > inherits page > > protected file as HttpPostFile > > Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > if file.PostedFile.ContentLength > 0 then > dim path as string = "c:\myserver\someRepository\" + > System.IO.Path.GetFileName(file.PostedFile.FileNam e) > file.PostedFile.SaveAs(path) > > dim connectionString as string = > "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" "& path > 'rest of the connection stuff here > > end if > end sub > > hope that helps, > Karl > > -- > MY ASP.Net tutorials > http://www.openmymind.net/ - New and Improved (yes, the popup is annoying) > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to > come!) > > > "Reggie" <NoSpam_chief123101@NoSpam_yahoo.com> wrote in message > news:jIydneXcYcBdOy_fRVn-2g@comcast.com... >> HI and TIA! What I'm trying to do is have my user click a button which >> opens the find file dialogue box. Once they find it I want to place the >> full path into a variable so that I can use it as the Source in my >> connection string. I've tried the HTML File Field control which allows >> me to navigate to the .mdb file and it places it into the File Field >> control on my page, however every attempt I try to place it in a variable >> gives me an error stating that the Page can't be located. I want >> something like so: >> >> >> Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As >> System.EventArgs) Handles Button1.Click >> >> Dim con As OleDbConnection >> >> Dim strFile As HttpPostedFile >> >> strFile = inpFileField.PostedFile >> >> con = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA >> Source=strFile") >> >> con.Open() >> >> End Sub >> >> Any help is appreciated. Thanks for your time! >> -- >> >> Reggie >> > > |
| All times are GMT. The time now is 05:16 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.