My.Computer.FileSystem.SpecialDirectories.MyDocuments in vs2008 data connection
-
Thursday, April 12, 2012 5:52 PM
I am trying to set the connection string in a data connection found under the server explorer.
I Have tryed the following syntax can this be done.
|My.Computer.FileSystem.SpecialDirectories.MyDocuments|\CDOL Datafiles\labor.mdb
Any Help would be greatly appreciated
Using VS 2008 and VB
Thanks
All Replies
-
Thursday, April 12, 2012 7:24 PM
short answer: probably not, but a windows path variable may work. there doesn't appear to be one for My Docs, but try this:
"%home%\My Documents\CDOL Datafiles\labor.mdb"
make sure you have the string quoted to avoid issues with spaces.
- Proposed As Answer by Mark Liu-lxfModerator Monday, April 16, 2012 6:12 AM
- Marked As Answer by Mark Liu-lxfModerator Friday, April 20, 2012 8:50 AM
-
Friday, April 13, 2012 2:35 AM
The special folders enumeration provides an index into the GetFolderPath method, which returns a string. You need to concatenate that string with your folder and file location to produce a full path. The IO namespace includes the required method.
Dim P As String = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "CDOL Datafiles\labor.mdb")
- Edited by AcamarMicrosoft Community Contributor Friday, April 13, 2012 2:37 AM sp
- Proposed As Answer by Mark Liu-lxfModerator Monday, April 16, 2012 6:12 AM
- Marked As Answer by Mark Liu-lxfModerator Friday, April 20, 2012 8:50 AM
-
Friday, April 13, 2012 6:29 AM
Going with the same solution that Acamar suggested but wrapped into an addition of My.Computer and excluding the pipe character as I have never needed a pipe include in a manual connection, try it both ways,
Namespace My Partial Class MyComputer Public ReadOnly Property MyDocuments() As String Get Return System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) End Get End Property ''' <summary> ''' Base name of database to open ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public Property DatabaseName As String ''' <summary> ''' Returns My Document\database to open ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public ReadOnly Property Database As String Get Return IO.Path.Combine(MyDocuments, DatabaseName) End Get End Property End Class End Namespace
Demo
My.Computer.DatabaseName = "labor.mdb" Console.WriteLine(My.Computer.Database)
If you felt so incline a property could be added to return your connection string if used in various places in your project.
Namespace My Partial Class MyComputer Public ReadOnly Property MyDocuments() As String Get Return System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) End Get End Property ''' <summary> ''' Base name of database to open ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public Property DatabaseName As String ''' <summary> ''' Returns My Document\database to open ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public ReadOnly Property Database As String Get Return IO.Path.Combine(MyDocuments, DatabaseName) End Get End Property Public ReadOnly Property ConnectionString As String Get Return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Database End Get End Property End Class End Namespace
KSG
- Proposed As Answer by Mark Liu-lxfModerator Monday, April 16, 2012 6:12 AM
- Marked As Answer by Mark Liu-lxfModerator Friday, April 20, 2012 8:50 AM
-
Friday, April 13, 2012 12:36 PM
Hi,
Or you have a standard DataDirectory placeholder than can be defined depending on each application needs by using AppDomain.CurrentDomain.SetData("DataDirectory","Whatever")
See http://social.msdn.microsoft.com/Forums/en/adodotnetdataproviders/thread/805bfd29-d864-4400-b353-bea13167f046 for details.
I never tried but if you apply the same technique you should be able even to include your own placeholders to be able to have something like :
|MdbDirectory|MyFile.mdb for one thing and |OtherPlace|something for something else...
Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
- Proposed As Answer by Mark Liu-lxfModerator Monday, April 16, 2012 6:12 AM
- Marked As Answer by Mark Liu-lxfModerator Friday, April 20, 2012 8:50 AM
-
Friday, April 13, 2012 12:52 PM
to clarify, you are trying to make a connection in Server Explorer, not write application code in an editor window, correct?
I believe that the reason your original attempt failed, is because Server explorer does not access your applications codebase, and doesn't understand what "My.Computer.FileSystem.SpecialDirectories.MyDocuments" is or means. just like if you entered it at the commandline, or typed it into an explorer path bar. if I am understanding your usecase, you could not use VB code to do this, but would instead have to limit yourself to windows shell code.
good luck

