簡體   English   中英

文件名,目錄名稱或卷標簽語法不正確。 (來自HRESULT的異常:0x8007007B)

[英]The filename, directory name, or volume label syntax is incorrect. (Exception from HRESULT: 0x8007007B)

當代碼尋找路徑時,我收到此錯誤,我不明白這種情況發生的原因,我認為我做得對。

碼:

 string newUri = ImageGalleryUri.Replace("ms-appdatalocal/", "");  //Replace this part of the string with a nonspace character.
        newUri = newUri.Replace("/", "\\");
        newUri = newUri.Replace("%20", " "); //Replace the ASCII code for space for an actual space. For some reason I'm getting invalid character error with %20.
        StorageFolder folder = Windows.Storage.ApplicationData.Current.LocalFolder;
        StorageFile storageFile = await folder.GetFileAsync(newUri);
        DataPackage dp = new DataPackage();    //Create the DataPackage containing the clipboard content.
        dp.SetBitmap(RandomAccessStreamReference.CreateFromFile(storageFile));
        Clipboard.SetContent(dp);
        await successDialog.ShowAsync();

錯誤在此行中:newUri = ms-appdata:\\ local \\ Books \\ Assets \\ Recursos para el docente \\ Matematicas \\ 9 \\ Esp \\ 1 \\ 0 \\ Geometria_Page_04.png

StorageFile storageFile = await folder.GetFileAsync(newUri);

也許試試這個:

newUri = Uri.EscapeDataString(newUri);

代替:

newUri = newUri.Replace("%20", " ");
  1. 調試以檢查字符串的實際值。
  2. Windows + R,然后復制字符串並查看它是否打開。
  3. 查看所有斜杠/反斜杠是否均已正確轉義(我認為在此處使用反斜杠不正確)。
  4. 創建一個名為file.txt的文件,然后嘗試以下操作:

    使用Windows.Storage;

StorageFile文件=等待StorageFile.GetFileFromApplicationUriAsync(“ ms-appdata:///local/file.txt”);

  1. 嘗試用您的字符串替換上面函數中傳遞的參數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM