Search Unity

Screenshot share issues - The specified path is invalid

Discussion in 'Windows' started by Joe_86, Feb 19, 2016.

  1. Joe_86

    Joe_86

    Joined:
    Jan 12, 2015
    Posts:
    6
    Hi there,

    i want to create a simple share button for my game on Windows Phone 8.1. But every time i use a file in the DataTransferManager, i get an exception: The specified path is invalid. (Exception from HRESULT: 0x800700A1)

    In unity, i create a Screenshot with following code:
    Code (CSharp):
    1. IEnumerator ShareScore() {
    2.         yield return new WaitForEndOfFrame();
    3.         Texture2D tex = new Texture2D(Screen.width, Screen.height);
    4.         tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
    5.         tex.Apply();
    6.         byte[] bytes = tex.EncodeToPNG();
    7.         Destroy(tex);
    8.  
    9.         string path = Application.persistentDataPath + "/" + "screenshot.png";
    10.         UnityEngine.Windows.File.WriteAllBytes(path, bytes);
    11.  
    12.         UnityEngine.WSA.Application.InvokeOnUIThread(() => {
    13.             krWP81ShareLib.WP81ShareService.Share(name, content, path);
    14.         }, false);
    WP81ShareService is my external Assembly (fake and deploy DLL). To share the picture, i use this code:
    Code (CSharp):
    1. if (!String.IsNullOrEmpty(mCurrentScreenshotPath)) {
    2.                 // Because we are making async calls in the DataRequested event handler,
    3.                 // we need to get the deferral first.
    4.                 DataRequestDeferral deferral = request.GetDeferral();
    5.                 try {
    6.                     StorageFile storageFile = await StorageFile.GetFileFromPathAsync(mCurrentScreenshotPath);
    7.                     RandomAccessStreamReference rasr = RandomAccessStreamReference.CreateFromFile(storageFile);
    8.                     request.Data.SetStorageItems(new StorageFile[] { storageFile });
    9.                 }
    10.                 catch (Exception ex) {
    11.                     throw new Exception(ex.Message + " --> Path: " + mCurrentScreenshotPath, ex);
    12.                 }
    13.                 finally {
    14.                     deferral.Complete();
    15.                 }
    16.             }
    I also tried other approches, like Application.CaptureScreenshot() or the SetBitmap() call on the Data-Field.
    Every time the same result. I guess there is something wrong in path argument? C:/Data/Users/DefApps/APPDATA/Local/Packages/a36ef184-e79d-4e58-9ea8-5e414cefeb86_635r5nbzd2de0/LocalState/screenshot.png

    I have the latest Unity Version (not beta).
    Any idea?
     
  2. Joe_86

    Joe_86

    Joined:
    Jan 12, 2015
    Posts:
    6
    OK, i found the problem. I used the wrong slashes all the time... With \ its all fine.
     
  3. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Take the guess work out of it and use

    Path.Combine(Application.persistentDataPath, "screenshot.png");

    Will use the correct method for the platform.
     
  4. Aseemy

    Aseemy

    Joined:
    Aug 22, 2015
    Posts:
    207
    fake and deploy dll?
    i have managed to save the screenshot.
    could you provide step by step instructions on how to share a screenshot in wp8.1