How can i fix this “Path not found” error?

时光毁灭记忆、已成空白 提交于 2019-12-13 18:17:42

问题


How can i solve this mobile application development problem?

While connecting to the DB

dataSource = \\..datafile.sdf

I get this error

"Path not found"

I am using serviceCE dll for data access.


回答1:


Windows CE has no concept of a relative path, so even if you "fixed" your invalid relative pathing it wouldn't work. You must use absolute paths.




回答2:


The path you you have typed it is a relative path. Windows CE/Mobile does not support relative paths.

It follows that since there is no concept of a current directory on a Windows Mobile device how would one locate a resource for which only a relative path is known? A .Net program always has access to the modules of which it is composed (usually a .Net component is composed of one module packaged in a DLL or EXE file). The following line will return the absolute path to the currently executing assembly.

string modulePath = this.GetType().Assembly.GetModules()[0].FullyQualifiedName;

with a little more code you can get the directory in which your program is running

Path.GetDirectoryName(this.GetType().Assembly.GetModules()[0].FullyQualifiedName)

Using that information you can build a proper path string to your resource.

note: If you are developing using the native APIS use the following: GetModuleFileName(GetModuleHandle(NULL), pszFullPath, MAX_PATH);




回答3:


I suppose there's something missing between \\ and ..




回答4:


"\.." doesn't make sense. It indicates your data is one level above the root folder, which doesn't exist. Besides, ctacke informs me in the comments that CE doesn't support relative paths anyway.

If relative paths were supported in your OS, the rest of my answer still applies. I'll leave it for future reference (and probably, since a lot of people seem to downvote without reading the entire post first) some loss of reputation. :-)

If the datafile is one level above the folder your app is in, the correct path would be '..\datafile.sdf'; in some programming languages you have to escape the backslash, so it would become '..\datafile.sdf'

Where is your data actually located, and where is your app? If the app is in \yourapp\folder\bin, and your data is in \yourapp\folder\data, the path from the app to the data would be '..\data\'. If the data file is in \yourapp\folder, the path would be '..\'. Again, you'll probably have to double the backslashes to escape them depending on the language you're using.



来源:https://stackoverflow.com/questions/638097/how-can-i-fix-this-path-not-found-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!