locked
Move File RRS feed

  • Question

  • hi all

    I have a camera app that takes a photo but it stores the file in a temp directory in roaming

    the full pathname is stored in File.path

    how do I move or copy the file into the pictures directory

    Any help appreciated

    Mark

    Tuesday, November 5, 2013 6:36 AM

Answers

  • Hi. Man, "storageFile" it is your "file". just variable name. like:

    StorageFile file = ...

    StorageFile storageFile = ...

    Next, you need to give Picture library access to your app in Package.appxmanifest. Just click twice on this file. Open Capabilities and find on left side Picture library. It must be active.

    And then, you can run your code.

                    StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);
                    if (file != null)
                    {
                        BitmapImage bitmapImage = new BitmapImage();
                        using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read))
                        {
                            bitmapImage.SetSource(fileStream);
                            Filenamebox.Text = file.Path;
                            await file.MoveAsync(Windows.Storage.KnownFolders.PicturesLibrary, "barr.jpg", Windows.Storage.NameCollisionOption.ReplaceExisting);
                        }
                        CapturedPhoto1.Source = bitmapImage;
                        appSettings[photoKey] = file.Path;


    • Edited by Oleg Kurzov Wednesday, November 6, 2013 5:21 AM
    • Marked as answer by wambaugh1 Wednesday, November 6, 2013 6:18 AM
    Wednesday, November 6, 2013 5:20 AM

All replies

  • Hi.

    In app manifest active "Picture library" capability.

    next, when you got the file from camera, do next code:

    await storageFile.MoveAsync(Windows.Storage.KnownFolders.PicturesLibrary, "some name", Windows.Storage.NameCollisionOption.ReplaceExisting);

    Where "storageFile" -> your picture.

    Also, add System namespace to usings:

    using System;

    Tuesday, November 5, 2013 7:50 AM
  • Hi there

    thanks for the reply

    I cant get it to enter

    I have used the system reference and have tried it in every place in the sub but when I type "storagefile." a list drops of available properties and there is no MoveAsync Option

    If I type the whole line in it has a wavy line under the whole line and the error says "an object reference is required for the non-static field, method or property.....) and then repeats the line

    Im very new to C# so dont understand the error

    Mark

    Tuesday, November 5, 2013 1:12 PM
  • Can you share your project?
    Tuesday, November 5, 2013 3:05 PM
  • https://skydrive.live.com/redir?resid=1B8C1CB2EA1F9BF7!125&authkey=!AHuELaHs9PxD1sM
    Tuesday, November 5, 2013 8:19 PM
  • Hi. Man, "storageFile" it is your "file". just variable name. like:

    StorageFile file = ...

    StorageFile storageFile = ...

    Next, you need to give Picture library access to your app in Package.appxmanifest. Just click twice on this file. Open Capabilities and find on left side Picture library. It must be active.

    And then, you can run your code.

                    StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);
                    if (file != null)
                    {
                        BitmapImage bitmapImage = new BitmapImage();
                        using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read))
                        {
                            bitmapImage.SetSource(fileStream);
                            Filenamebox.Text = file.Path;
                            await file.MoveAsync(Windows.Storage.KnownFolders.PicturesLibrary, "barr.jpg", Windows.Storage.NameCollisionOption.ReplaceExisting);
                        }
                        CapturedPhoto1.Source = bitmapImage;
                        appSettings[photoKey] = file.Path;


    • Edited by Oleg Kurzov Wednesday, November 6, 2013 5:21 AM
    • Marked as answer by wambaugh1 Wednesday, November 6, 2013 6:18 AM
    Wednesday, November 6, 2013 5:20 AM
  • Oleg

    Your the man thank you very much

    Mark

    Wednesday, November 6, 2013 6:18 AM