Locate File Diologe

Discussion in 'ASP .Net' started by Reggie, Jun 17, 2005.

  1. Reggie

    Reggie Guest

    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
     
    Reggie, Jun 17, 2005
    #1
    1. Advertising

  2. Reggie

    Karl Seguin Guest

    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

    --
    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:...
    > 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
    >
     
    Karl Seguin, Jun 17, 2005
    #2
    1. Advertising

  3. Reggie

    Reggie Guest

    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:...
    > 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
    >
    > --
    > 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:...
    >> 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
    >>

    >
    >
     
    Reggie, Jun 18, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    452
    John Timney \(ASP.NET MVP\)
    Apr 8, 2005
  2. MattC
    Replies:
    4
    Views:
    8,008
    Roedy Green
    Sep 18, 2005
  3. shawnk
    Replies:
    0
    Views:
    406
    shawnk
    Apr 29, 2005
  4. Gol Yass
    Replies:
    1
    Views:
    264
    opalpa http://opalpa.info
    Oct 10, 2006
  5. Lakshmi

    WinAPI to locate a file in directory

    Lakshmi, Sep 22, 2004, in forum: C Programming
    Replies:
    2
    Views:
    316
    Lakshmi
    Sep 22, 2004
Loading...

Share This Page