locked
Upload file to server on change?

    Question

  • Hello, we're looking for a way for a Metro style app to monitor files in a temporary folder that has been downloaded by our application. And then upload them to the server when the files are changed by the user in another program.

    It looks like the only way to open a file in another program is to save the file to disk and then use the Windows.System.Launcher class to open the file. To know when the user has edited the file we have tried to use the Windows.Storage.Search.StorageFolderQueryResult.ContentsChanged event but it doesn't do anything when the files are changed.

    We know there is functionality for callbacks in .NET when files are edited but it doesn't seem to exist in WinRT. Using a background task to continously poll the filesystem for changes doesn't seem like a viable solution because it is only allowed to run every 15 minutes.

    Are we missing some other way of doing this? There has to be other applications trying to do the same thing, Dropbox maybe? Or how does SkyDrive synchronize files?

    Friday, April 13, 2012 2:12 PM

Answers

  • We found the class Windows.Storage.Provider.CachedFileUpdater that has the function setUpdateInformation where you can register files that you want to get a callback for if the file is being accessed (before read or after write).

    To allow your application to answer callbacks from the Cached File Updater you need to add it to the supported declarations in the application manifest under the Declarations tab. This works similar to the File Picker callbacks.

    Skydrive doesn't seem to use this functionality in the version that we have tried.

    • Marked as answer by iipax Thursday, April 19, 2012 12:39 PM
    Thursday, April 19, 2012 12:39 PM

All replies

  • Why do you need to monitor the files more than every 15 minutes?  It is a deliberate design feature that background tasks cannot run more than once in a 15 minute period, so I don't think that you have a good application for Metro design.  However, if you don't need to couple the UI design of your application (Metro app) with a file change notifications, you could install a service that monitors for FCN (file chnage notification) and then uploads the changes.  You can't do IPC with the service but I don't think you would need to do that.  Keep in mind, however, that Store applications should not depend on same-box external services.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator

    Monday, April 16, 2012 7:41 PM
    Moderator
  • Whats the purpose of your app? Why are you downloading files into the temp folder? 

    As an alternative your app could act as FilePicker and provide files to other apps. Then you could register as FileUpdate listener and get notified by Windows when the file the user picked from your app was changed. You could then queue the file for upload.

    Thats how SkyDrive does it.

    Tuesday, April 17, 2012 8:46 AM
  • The purpose of the app is to be a native Windows 8 client to a Java Server for case management (sorry I don't know the correct English term). The cases have documents connected to it. 
    We will download the documents (office, text or other) to the client from the server so that the user can edit them.
    If the user has edited the document we want to get notified of it and upload it to the server (without starting our app again).
    We put the documents in the app temp folder so the user doesn't have the documents saved locally (the ideal solution would be not to save them to disk at all).

    "As an alternative your app could act as FilePicker and provide files to other apps. Then you could register as FileUpdate listener and get notified by Windows when the file the user picked from your app was changed. You could then queue the file for upload."

    Do you know where there is a code example of this?

    The problem with the 15-minute delay of the background task is that if you edit a document in the 15-minute you can have turned off your computer and go on holiday the document don't get uploaded to the server again.

    Tuesday, April 17, 2012 2:03 PM
  • Tuesday, April 17, 2012 4:40 PM
  • The solution using the storage provider to provide a filepicker would not work with non-metro apps, correct? Could the user press a button inside our application to open a file, as in could we use Windows.System.Launcher.launchFileAsync in combination with the FileUpdate listener?

    EDIT:
    After some quick testing with Skydrive and editable PDFs we've discovered that if you open a file from within the Skydrive application and then edit the document and after you save it Skydrive won't upload the new version. The only way to make this work is to open the file from the PDF reader using the Skydrive filepicker. We have a hard time believing that Skydrive is intended to work this way!

    • Edited by iipax Wednesday, April 18, 2012 12:39 PM
    Wednesday, April 18, 2012 12:22 PM
  • This would be interesting to know for me too. Maybe Skydrive just not updates the remote file immediately when you change it externally without using SkyDrive as the filepicker?
    Wednesday, April 18, 2012 1:07 PM
  • We found the class Windows.Storage.Provider.CachedFileUpdater that has the function setUpdateInformation where you can register files that you want to get a callback for if the file is being accessed (before read or after write).

    To allow your application to answer callbacks from the Cached File Updater you need to add it to the supported declarations in the application manifest under the Declarations tab. This works similar to the File Picker callbacks.

    Skydrive doesn't seem to use this functionality in the version that we have tried.

    • Marked as answer by iipax Thursday, April 19, 2012 12:39 PM
    Thursday, April 19, 2012 12:39 PM