如果您的Windows Mobile版本下7(窗口響度單位)工作檢查: C#代碼:
public static string GetFolderPath(SpecialFolder folder)
{
//buffer to fill with path
StringBuilder path = new StringBuilder(MaxPath);
//pass stringbuilder and folder identifier to api function
if(!Convert.ToBoolean(SHGetSpecialFolderPath(IntPtr.Zero,
path, (int)folder, 0)))
{
throw new Exception("Cannot get folder path!");
}
return path.ToString();
}
[DllImport("coredll", EntryPoint="SHGetSpecialFolderPath",
SetLastError=false)]
internal static extern int SHGetSpecialFolderPath(IntPtr hwndOwner,
StringBuilder lpszPath, int nFolder, int fCreate);
VB.net代碼:
Public Shared Function GetFolderPath(folder As SpecialFolder) As String
'buffer to fill with path
Dim path As New StringBuilder(MaxPath)
'pass stringbuilder and folder identifier to api function
If Not Convert.ToBoolean(SHGetSpecialFolderPath(IntPtr.Zero, path, CInt(folder), 0)) Then
Throw New Exception("Cannot get folder path!")
End If
Return path.ToString()
End Function
<DllImport("coredll", EntryPoint := "SHGetSpecialFolderPath", SetLastError := False)> _
Friend Shared Function SHGetSpecialFolderPath(hwndOwner As IntPtr, lpszPath As StringBuilder, nFolder As Integer, fCreate As Integer) As Integer
End Function
你得Import System.Environment
看到特殊文件夾和 Import System.Runtime.InteropServices
以查看DllImport
有關詳細信息:http://msdn.microsoft.com/en-us/library/aa446567.aspx#spfiles_topic_03
請,如果它的工作記住我的答案右
假設你對你的問題的標題是正確的,在移動環境中'Progam Files'不存在,並且你的數據庫文件應該在你的應用根路徑中。 – balexandre 2012-02-20 08:20:11