referencing My Documents Folder in connection string

K

Kerry de Vent

I am building a VB 2008 application that interfaces with a MS Access
database. I wish to change the connection string so It looks in the user's
My Documents folder rather than the current directory.

The problem is that the My Documents directory will be in a different place
depending on the user's OS and setup. Is there a way to code the connection
string so that it goes to the my documents directory wherever it may be?


connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=|DataDirectory|\studentSurvey.accdb"

thanks,
Kerry


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4441 (20090919) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
A

Armin Zingler

dotNetDave said:
You can always replace "|DataDirectory|" with
My.Computer.FileSystem.SpecialDirectories.MyDocuments

Or straight Environment.GetFolderPath
 
K

Kerry de Vent

When I have the connection string as

ConnectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=|My.Computer.FileSystem.SpecialDirectories.MyDocuments|\studentSurvey.accdb"

I get an error message.

Is the app.config file the correct place to put the connection string or do
I need to do it at runtime in the code?




dotNetDave said:
You can always replace "|DataDirectory|" with
My.Computer.FileSystem.SpecialDirectories.MyDocuments

David

======================================
David McCarter [Microsoft MVP]
www.dotNetTips.com
David McCarter''''s .NET Coding Standards available at:
http://codingstandards.notlong.com


Kerry de Vent said:
I am building a VB 2008 application that interfaces with a MS Access
database. I wish to change the connection string so It looks in the
user's
My Documents folder rather than the current directory.

The problem is that the My Documents directory will be in a different
place
depending on the user's OS and setup. Is there a way to code the
connection
string so that it goes to the my documents directory wherever it may be?


connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=|DataDirectory|\studentSurvey.accdb"

thanks,
Kerry


__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4441 (20090919) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4445 (20090921) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4445 (20090921) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
F

Family Tree Mike

Kerry said:
When I have the connection string as

ConnectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=|My.Computer.FileSystem.SpecialDirectories.MyDocuments|\studentSurvey.accdb"

You need to build the string dynamically, with String.Format for
example. The My.Computer.FileSystem.SpecialDirectories.MyDocuments
property is returning a string in the application. You put it's results
in the connection string.
 

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

Similar Threads

My Documents 10
Cannot access My documents with Vista 64 2
Windows XP share connection 1
My Most Recent Documents List 2
Word Pages 1
outlook 2003 favourite folder 3
String with UTF8 in it? 1
redirect folders 5

Top