locked
Saving a image using CopyAsync() RRS feed

  • Question

  • This is the the steps on how its goes:

    1) User pick an image than it will show the path in a textblock

    2) User click save button it will store the image to a folder inside Documents using the CopyAsync(new path)

    3) Than it store other details in to database. It will store the new path of the image to the database.

    Thanks, Smiths

    Thursday, August 15, 2013 5:29 AM

Answers

  • Hi,Reid

    You can just declare a default folder.Before  you can open folder in the Picture library, you

    must declare the necessary capabilities in your app manifest.

    Then you can code like this:

     StorageFolder picturesFolder = KnownFolders.PicturesLibrary;
                    StorageFolder folder = await picturesFolder.GetFolderAsync("pictures");
                    var outputfile = await file.CopyAsync(folder, file.Name.ToString(), NameCollisionOption.ReplaceExisting);

    Best Wishes!

    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    • Edited by Anne Jing Monday, August 19, 2013 1:32 PM from
    • Marked as answer by Reid Smiths Tuesday, August 20, 2013 3:37 AM
    Monday, August 19, 2013 1:31 PM

All replies

  • so what's your question?

    You might want to lookup StorageItemAccessList and FutureAccessList for remembering the location of the files. (In WinRT it's best practice to use these lists and not to store a path.)


    Life is unsure - always eat the dessert first!

    Thursday, August 15, 2013 8:43 AM
  • What is the question ? In addition to Michael's reading (you'll probably want to use FutureAccessList), if you are trying to do what you are describing it should looks like that :

    Windows.Storage.Pickers.FileOpenPicker picker = new Windows.Storage.Pickers.FileOpenPicker(); picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary; picker.FileTypeFilter.Add(".jpg"); picker.FileTypeFilter.Add(".png"); var file = await picker.PickSingleFileAsync(); if (file != null) { var folder = await store.GetFolderAsync(directoryName); var outputfile = await stream.CopyAsync(folder, "new_name", NameCollisionOption.ReplaceExisting);

    SavedToDb(outpufile.Path); }



    Cyprien Autexier

    Thursday, August 15, 2013 9:46 AM
  • The question is how I do the CopyAsync ? Is it when I pick the image the path than it CopyAsync the path ? Thanks.

    Thanks, Smiths

    Friday, August 16, 2013 1:16 AM
  • Here is the code:

    Windows.Storage.Pickers.FolderPicker store = new Windows.Storage.Pickers.FolderPicker();
    var folder = await store.PickSingleFolderAsync();
    var outputfile = await file.CopyAsync(KnownFolders.DocumentsLibrary, file.Name.ToString(), NameCollisionOption.ReplaceExisting);

    The folder how do I specify the folder there I don want the user to pick the folder. The folder is in Documents. I want to save inside the documents. Thanks


    Thanks, Smiths

    Friday, August 16, 2013 2:03 AM
  • Hi,Reid

    As your description,you want to save an image file to the folder which is the sub-folder in a floder.Am I right?

    Do you want to  use the FolderPicker to open a folder in your picture Document Library ?If so,you can code like this:

    Windows.Storage.Pickers.FolderPicker folderPicker = new Windows.Storage.Pickers.FolderPicker();
                    folderPicker.FileTypeFilter.Add(".docx");
                    folderPicker.FileTypeFilter.Add(".xlsx");
                    folderPicker.FileTypeFilter.Add(".pptx");
                    StorageFolder folder = await folderPicker.PickSingleFolderAsync();
                    var outputfile = await file.CopyAsync(folder, file.Name.ToString(), NameCollisionOption.ReplaceExisting);

    You can pick the sub-folder and then save the image file into it with the above codes .

    If you have any questions,I am willing to help you!

    Best Wishes!


    • Edited by Anne Jing Monday, August 19, 2013 8:07 AM from
    Monday, August 19, 2013 8:06 AM
  • Can I just declare a default folder ?

    Thanks, Smiths

    Monday, August 19, 2013 9:26 AM
  • Hi,Reid

    You can just declare a default folder.Before  you can open folder in the Picture library, you

    must declare the necessary capabilities in your app manifest.

    Then you can code like this:

     StorageFolder picturesFolder = KnownFolders.PicturesLibrary;
                    StorageFolder folder = await picturesFolder.GetFolderAsync("pictures");
                    var outputfile = await file.CopyAsync(folder, file.Name.ToString(), NameCollisionOption.ReplaceExisting);

    Best Wishes!

    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    • Edited by Anne Jing Monday, August 19, 2013 1:32 PM from
    • Marked as answer by Reid Smiths Tuesday, August 20, 2013 3:37 AM
    Monday, August 19, 2013 1:31 PM
  • Thanks, it works. But if I running the app I cannot save anything in the app folder right ? And also I save the path in db, when I want to retrieve the data how do I point to the folder to let let it retrieve ? How do I use the Uri _baseUri ? Thanks.

    Thanks, Smiths



    • Edited by Reid Smiths Tuesday, August 20, 2013 4:21 AM Edit
    Tuesday, August 20, 2013 3:38 AM