隔离存储中不支持给定路径的格式

时间:2014-11-07 10:41:18

标签: c# windows-phone-8

我想在上传到服务器之前计算我的文件大小,然后我通过创建文件夹将文件保存在隔离存储中。现在我想得到计算文件大小的路径,但是它给出了错误"不支持给定路径的格式"

我的代码是:

string filePath = Path.Combine(FolderName, FileName);
string fp = @"ms-appdata:///local//" + imageFolder + "//" + fName; // here I tried "/" and try to append "filePath " directly still throwing same error

FileInfo info = new FileInfo(fp); ////Here it is throwing error "The given path's format is not supported"

var fileLength = new System.IO.FileInfo(fp).Length;
int image_file_size = Convert.ToInt32(fileLength);

此路径的正确格式是什么?

2 个答案:

答案 0 :(得分:1)

当您在XAML中获取代码时,请考虑这种路径。如果你想使用System.IO

然后你需要像这样构建路径

string dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite");   
FileInfo info = new FileInfo(dbPath);

enter image description here

答案 1 :(得分:1)

此代码正常运行

string filePath = Path.Combine(FolderName, FileName);
string FilePath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, filePath);
FileInfo info = new FileInfo(FilePath);
var fileLength = new System.IO.FileInfo(FilePath).Length;
int image_file_size = Convert.ToInt32(fileLength);