Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If a file located on Properties.Resouce, what the path about it?

C#
string strCon ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath +"....


whats the filepath should to write down?
Posted
Updated 18-Mar-15 18:23pm
v2

by default files in the project resource are embedded in the assembly. so you can access them as byte[] using the code
[ProjectName].[Resources].[FileName]

which in your case won't work because you need the file path.So you have to explicitly tell the compiler to copy the file to the application directory. Just select the file in the resources folder, inside the solution explorer, right click and "Properties". That would give you an option "Copy to output directory" set it to "Copy always". then when you build your application it would pop up in the output directory under "Resources" folder.
Modify your code as below to accommodate the changes

string strCon ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Windows.Forms.Application.StartupPath+"\\Resources\\"+[filename]+"....


hope that helped
good luck
 
Share this answer
 
Comments
Kean(cn) 13-Sep-10 22:43pm    
thank you!
Actually i want the program pass to user with only one file, dont contain such as DLL or other files, the samll Database shouldnt show to user even had been encrypted. the program just read the txt fiel not edit it.
Hi Kean,

You can access the file which is inside the Properties.Resouce using following code:

..\bin\Debug\{YourFileName}


Please do let me know, if you have any doubt.
Please provide Vote if this would be helpful to you.

Thanks,
Imdadhusen
 
Share this answer
 
v2
Comments
Abhishek Sur 13-Sep-10 5:44am    
I think you shouldn't be putting a database file within Properties folder.
It is better to put it in Debug folder directly.
Kean(cn) 13-Sep-10 22:36pm    
I want set the program to user only one file, dont contain DLL or other files, so i put the small database file in the Resource, and the program just read the file to a Dataset, not write or update it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900