Results 1 to 20 of 20

Thread: How do i do app.path in VB.NET

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2002
    Posts
    61

    How do i do app.path in VB.NET

    Hi all,


    How can i use App.path in VB.NET.App gives error as name 'App' is not decalred.

    what shall i do.
    I tried to import system.windows.Forms.application

    but i could not make it correct.

    Pl give me a solution


    Dim Conn As ADODB.Connection
    Dim objword As Word.Application
    Conn = New ADODB.Connection()
    Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.path & "\testdb.mdb;Mode=Share Deny None"
    Conn.Open()

    Thanks.

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Try Application.StartupPath(), or something like that, it is in the Application namespace.

  3. #3
    Member HumanCompiler's Avatar
    Join Date
    Dec 2002
    Location
    Decatur, IN USA
    Posts
    52
    this also works...

    AppDomain.CurrentDomain.BaseDirectory
    -Erik Porter
    .NET MVP

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    many choices are there :
    VB Code:
    1. '''''''1
    2. strAppPath = Application.StartupPath
    3. ''''''''2
    4. Imports System.Reflection
    5. mAppPath = System.Reflection.Assembly.GetExecutingAssembly.Location
    6. '''''''''3
    7. Public Apath As String = System.Environment.CurrentDirectory
    8. ''''''''''4
    9. Imports System.IO
    10. Dim dir As Directory
    11. dir.GetCurrentDirectory()

    and many ways to do that.So pick whatever you like.
    Pirate

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2002
    Posts
    61

    Thanks>it works fine but facing new problem

    Hi,

    Thanks .It works well now but facing new problem.

    When i try to run the program it could not find the database application path and gives an error

    the error is:

    'System.runtime.interopservices.comException'occured in MArana form.exe

    additional inforamtion for error is:
    pl check the path name and spelled correctly.

    the code:


    Imports System.IO
    Imports System.Reflection

    Imports System.Windows.Forms.Application
    Imports System.Runtime.InteropServices.COMException



    Public Class Form1
    Inherits System.Windows.Forms.Form

    #Region " Windows Form Designer generated code "


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim mAppPath As String
    mAppPath = System.Reflection.Assembly.GetExecutingAssembly.Location

    Dim Conn As ADODB.Connection
    Dim objword As Word.Application

    Conn = New ADODB.Connection()


    Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mAppPath & "\testdb.mdb;Mode=Share Deny None"
    Conn.Open()


    thanks

  6. #6

    Thread Starter
    Member
    Join Date
    Nov 2002
    Posts
    61

    where shall i store mdb file in VB.NET

    I have stored my testdb.mdb file in maranaform folder. and sametime i stored in bin folder also.But i am facing same problem.
    the error is:

    An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in MaranaForm.exe

    Additional information: 'C:\ram\mortgage\MaranaForm\bin\MaranaForm.exe\testdb.mdb' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
    the code is:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim mAppPath As String
    mAppPath = System.Reflection.Assembly.GetExecutingAssembly.Location

    Dim Conn As ADODB.Connection
    Dim objword As Word.Application
    Conn = New ADODB.Connection()


    Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mAppPath & "\testdb.mdb;Mode=Share Deny None"
    Conn.Open()


    Please give me a solution.

    Thanks.

  7. #7
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    I am not one hundred percent sure, but try changing this:
    "\testdb.mdb

    to this:
    @"\testdb.mdb

    or
    "\\testdb.mdb

    You are using a backslash constant in your string. To stop all backslash constants from being read, you use the @ in front of the literal string. Or you can continue using backslash constants in your strings, and use the proper one, which is \\, for the backslash character.

  8. #8
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Oops, never mind, I thought I was in the C# forum...lol.

  9. #9
    Member HumanCompiler's Avatar
    Join Date
    Dec 2002
    Location
    Decatur, IN USA
    Posts
    52
    Can I ask why you're trying to use ADO with .NET? You should be using ADO.NET with .NET

    Instead of using COM Interop to access ADODB, use the System.Data.OleDb Namespace to access your Acesss file
    -Erik Porter
    .NET MVP

  10. #10

    Thread Starter
    Member
    Join Date
    Nov 2002
    Posts
    61
    HI,

    I could not solve the same problem.I tried your idea.But facing same problem.

    Please help me out.

    Thanks.

  11. #11
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    is your db file under the folder \bin ??

  12. #12
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    yes it is
    anyways, this line of code returns this "path and name of the exe of your proj

    VB Code:
    1. Dim mAppPath As String
    2.         mAppPath = System.Reflection.Assembly.GetExecutingAssembly.Location

    try this :

    VB Code:
    1. Dim mAppPath As String = (Path.GetFullPath & "\" & "myfile.mdb")

  13. #13

    Thread Starter
    Member
    Join Date
    Nov 2002
    Posts
    61
    Yes I keep the mdb fils file in both bin folder and maranaform folder.

  14. #14
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I'm sorry I couldn't see that

  15. #15

    Thread Starter
    Member
    Join Date
    Nov 2002
    Posts
    61
    Dim mAppPath As String = (Path.GetFullPath & "\" & "myfile.mdb")

    Argument not specified for parameter'path' of 'public shared overloads function get fullPath(Path as String) as string'


    I tried your idea that gives error on tooltip(Argument not specified for parameter'path' of 'public shared overloads function get fullPath(Path as String) as string').

  16. #16
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    VB Code:
    1. Dim mAppPath As String = Path.Combine(Application.StartUpPath,"myfile.mdb")

  17. #17
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    guess gives the same result as mine but seems clearer

  18. #18

    Thread Starter
    Member
    Join Date
    Nov 2002
    Posts
    61
    Hi,

    I tried path.combime.But it gives different error now.

    An unhandled exception of type 'System.NullReferenceException' occurred in microsoft.visualbasic.dll

    Additional information: Object variable or With block variable not set.

    Imports System.Data
    Imports System.Reflection
    Imports System.Windows.Forms.Application
    Imports System.Runtime.InteropServices.ExternalException

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim sApppath As String

    LblDate.Text = firstdate


    Dim conn As ADODB.Connection
    conn = New ADODB.Connection()
    Dim objword As Word.Application
    Dim path As Object
    'sApppath = System.Reflection.Assembly.GetExecutingAssembly.Location
    sApppath = System.Windows.Forms.Application.StartupPath
    sApppath = path.CombineApplication.StartupPath, "Addressdb.mdb")

    conn.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data source=" & sApppath & "\Addressdb.mdb;Mode=Share deny None"
    conn.Open()

    End Sub

  19. #19
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    VB Code:
    1. Dim conn As ADODB.Connection
    2. conn = New ADODB.Connection()
    3. Dim objword As Word.Application
    4. 'I took out some unneeded stuff here
    5. sApppath = IO.path.Combine(Application.StartupPath, "Addressdb.mdb") 'you forgot a ( at the start here
    6.  
    7. conn.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;Data source=" & sApppath & ";Mode=Share deny None" 'the database name is already in the sApppath varaible so no need for it at the end
    8. conn.Open()

  20. #20

    Thread Starter
    Member
    Join Date
    Nov 2002
    Posts
    61
    Hi,

    Thanks.It Works fine.Thank you very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width