Locate File Diologe

R

Reggie

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!
 
K

Karl Seguin

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.FileName)
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
 
R

Reggie

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 said:
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.FileName)
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top