locked
CachedFileUpdaterUI.FileUpdateRequested event never gets fired.

    Question

  • Hello.

    I want to implement the FileSavePicker contract thus other apps could save their documents directly into my app. I have attached an event handler to the FileSavePickerActivatedEventArgs.FileSavePickerUI.TargetFileRequested event that is fired when the user wants to save a file to my app. Here I set TargetFileRequestedEventArgs.Request.TargetFile to a StorageFile which is a temporary file created in local folder. Then I'd like to react on the completion of the file saving process by using CachedFileUpdater.SetUpdateInformation and there seems to be one problem occurs.

    When the calling app write smth to my local file, OnCachedFileUpdaterActivated() method on App.xaml.cs gets called, where I subscribing on CachedFileUpdaterUI.FileUpdateRequested event which is never gets fired.

    private async void OnTargetFileRequested(FileSavePickerUI sender, TargetFileRequestedEventArgs e) { var deferral = e.Request.GetDeferral(); var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(sender.FileName, CreationCollisionOption.GenerateUniqueName); e.Request.TargetFile = file; CachedFileUpdater.SetUpdateInformation(file, file.Name, ReadActivationMode.NotNeeded, WriteActivationMode.AfterWrite, CachedFileOptions.RequireUpdateOnAccess); deferral.Complete(); }

            // App.xaml.cs
            protected override void OnCachedFileUpdaterActivated(CachedFileUpdaterActivatedEventArgs args)
            {
                args.CachedFileUpdaterUI.FileUpdateRequested += CachedFileUpdaterUI_FileUpdateRequested;
                Debug.WriteLine("OnCachedFileUpdaterActivated()");
            }

            // This method nver gets called!
            void CachedFileUpdaterUI_FileUpdateRequested(CachedFileUpdaterUI sender, FileUpdateRequestedEventArgs args)
            {
                Debug.WriteLine("OnFileUpdateRequested()");
            }


    Here I used two samples FilePickerContracts and FilePickers. I slightly modified the first one adding the code above. And as a client app I used the second sample:

                    FileSavePicker savePicker = new FileSavePicker();
                    savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
                    savePicker.FileTypeChoices.Add("Plain Text", new List<string>() { ".txt" });
                    savePicker.SuggestedFileName = "New Document";
                    StorageFile file = await savePicker.PickSaveFileAsync();
                    if (file != null)
                    {
                        CachedFileManager.DeferUpdates(file);
                        await FileIO.WriteTextAsync(file, file.Name);
                        FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);
                    }
    If it helps I upload full code on skydrive.



    Monday, August 6, 2012 4:59 PM

Answers

  • If FileUpdateRequested  is never called, but OnTargetFileRequested is, it might be that the app implementing the CachedFileUpdater is not calling Window.Activate. If you look in the sample, the events are implemented in a page that calls Window.Current.Activate.
    Wednesday, November 14, 2012 5:31 AM

All replies

  • I might be missing siomething, but I don't see in this code how to access the file which was saved to the FilePickerContracts app.  If that same file isn't accessed, then the FileUpdateRequested event won't fire. 

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, August 7, 2012 2:47 PM
    Moderator
  • Hi, Matt!

    That file is accessed in code above by call of FileIO.WriteTextAsync(file, file.Name). Also function in the next line (CachedFileManager.CompleteUpdatesAsync(file)) doesn't return until I terminate the FilePickerContracts app.

    In other words, I want to achieve rather simple functionality here. Once the file has been saved in my app (using File Picker Contracts) I want to receive notification that all writing operations to the local copy of file's been completed and then upload that file on the server.

    Wednesday, August 8, 2012 9:28 AM
  • You're right - it never fires, and I can't figure out why.  I'm talking to our people about this.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, August 9, 2012 4:22 PM
    Moderator
  • Serg - sorry for the delay.  I asked about this and got this answer:

    Typically this FileUpdateRequested event is fired after CFU activation when either another app calls CompleteUpdatesAsync on a file provided by your app or another app access a file from the MRU or Future Access List that came from your app.  You can check out our RTM File Picker and File Picker Contracts SDK Samples that demonstrate these scenarios.  Note: Your app must set the UpdateInformation on the file before it is passed to another application via the Open/Save Picker Contract or File Association Launch in order for CFU to work.

    Please let me know if this doesn't help.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, August 30, 2012 2:42 PM
    Moderator
  • If FileUpdateRequested  is never called, but OnTargetFileRequested is, it might be that the app implementing the CachedFileUpdater is not calling Window.Activate. If you look in the sample, the events are implemented in a page that calls Window.Current.Activate.
    Wednesday, November 14, 2012 5:31 AM
  • This was my problem : thanks a lot !

    Jonathan ANTOINE - Découvrez mon livre sur MVVM: http://goo.gl/N6Tmn - http://www.jonathanantoine.com

    Sunday, March 24, 2013 4:04 PM
  • Hello,

    This may interest you too : http://www.jonathanantoine.com/2013/03/25/win8-the-cached-file-updater-contract-or-how-to-make-more-useful-the-file-save-picker-contract/


    Regards


    Jonathan ANTOINE - Découvrez mon livre sur MVVM: http://goo.gl/N6Tmn - http://www.jonathanantoine.com

    Monday, March 25, 2013 1:13 PM