C# 如何在Windows CE设备上指定文件的路径?
我从测试应用程序复制了一些代码:C# 如何在Windows CE设备上指定文件的路径?,c#,sql-server-ce,windows-ce,filepath,windows-embedded-compact,C#,Sql Server Ce,Windows Ce,Filepath,Windows Embedded Compact,我从测试应用程序复制了一些代码: const string sdfPath = @"C:\WebAPIClient\WebAPIClient\bin\Debug\DBPlatypusCompactDB.sdf"; string dataSource = string.Format("Data Source={0}", sdfPath); int countAdded = 0; if (!File.Exists(sdfPath)) . . . …在那里效果很好;但在尝试将其转换为在Wi
const string sdfPath = @"C:\WebAPIClient\WebAPIClient\bin\Debug\DBPlatypusCompactDB.sdf";
string dataSource = string.Format("Data Source={0}", sdfPath);
int countAdded = 0;
if (!File.Exists(sdfPath))
. . .
…在那里效果很好;但在尝试将其转换为在Windows CE设备上运行的项目中使用时:
const string sdfPath = @"Computer\WindowsCE\\\Program Files\hhs\DBPlatypusCompactDB.sdf";
. . .
…(这是我从Windows资源管理器复制的路径(exe部署到的文件夹,没有子文件夹)),我得到“未找到路径”或“路径无效”或类似信息
我该如何指定路径?不太清楚您要做什么,因此这里有一些通用的指针:
\
)字符开头\Program Files\hhs\mydatabase.sdf
My Device\Program Files\foo.bar
)不是桌面上任何文件API都可以解析的路径。如果您想从PC应用程序访问设备文件,则必须使用类似RAPI的工具在本地提取文件,然后使用本地副本如果要在设备上运行,请使用以下代码: const string sdfPath=System.IO.Path.GetDirectoryName(System.Reflection.Assembly.getExecutionGassembly().GetName().CodeBase+@“\FolderName\Filename.*” 但是,您需要将文件夹名复制到程序文件路径上的设备请参见图像文件夹示例:
“计算机”是桌面上Windows资源管理器所说的,但从设备本身来看,它是“\\Program Files\\hhs\DBPlatypus.sdf”,这很好;谢谢!Windows CE不理解相对路径,因为没有“进程的当前目录”的概念在Windows CE中。欢迎使用堆栈溢出!当给出答案时,最好给出正确答案。