首页 文章

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

提问于
浏览
2

我想在上传到服务器之前计算我的文件大小,之后我通过创建文件夹将文件保存在独立存储中 . 现在我想得到计算文件大小的路径,但它给出错误“不支持给定路径的格式”

我的代码是:

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 回答

  • 1

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

    然后你需要 Build 这样的路径

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

    enter image description here

  • 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);
    

相关问题