none
[UWP]How to allow a Windows Store app to edit deployed content files? RRS feed

All replies

  • Hi,

    There are a few questions about your problem.

    Where is the Templates folder placed? Inside your app's local folder or in some other places? 

    You said that it worked file with a click-once deployment, do you mean the app is sideloaded or you install the app via Visual Studio?

    What's your real requirement? Could you explain it with more details?

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 30, 2018 6:12 AM
    Moderator
  • Hello, Rot

    The folder is contain inside the local apps folder.

    Regular click-once deployments. http://www.frozenelephant.com/symbiotic/publish.htm

    My requirements are that the end-user should be able to modify the files inside the templates folder.

    Thanks,

    Eric


    Eric

    Friday, November 30, 2018 11:04 AM
  • Hi,

    Let me clarify something. So I know the folder is in local folder.

    Do you mean the app works well if you sideload your app and it gives error message when you download and install it from the store?

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 3, 2018 9:26 AM
    Moderator
  • no, I'm NOT side loading anything.

    As part of the application, there is a folder included called "Templates" which includes a bunch of text files. The user should be able to open these with a text editor and modify them, yet the user can not and and windows says they do not have permission.


    Eric

    Monday, December 3, 2018 4:15 PM
  • Hi,

    Sorry for the delay.

    If you are loading other file of the app's local folder, does this error still exist?

    Could you please show me the code snippet that you used to access the files? 

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 5, 2018 8:15 AM
    Moderator
  • I'm not using code to open or modify them.

    If a user tries to modify (save changes) the text files with note pad, windows says they do not have permission.

    I don't know how I can be any clearer on this...


    Eric

    Wednesday, December 5, 2018 2:07 PM
  • Hi,

    So you are trying to modify these file in file explorer instead of doing it inside the app right?

    Does the path look like: C:\Users\The user that you are logged in with\AppData\Local\Packages\Your app's name ?

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 7, 2018 9:28 AM
    Moderator
  • yes but the folder is:

    C:\Program Files\WindowsApps\40329FrozenElephantInc.SymbioticCodeGenerator_2.0.10.0_x64__59hzgejs1kvn0\SymbioticHelper\Templates

    I deploy pre-defined template files, but the user should be able to add, modify or create new ones. The template files are similar to Micrsoft's T4, but simple to use and understand.


    Eric

    Friday, December 7, 2018 11:55 AM
  • The install package is read-only there is no way to allow the user to write there.

    The recommended practice for templates such as you're using is to include unmodifiable base templates in the package and then copy them to a user-modifiable location on first run. That location will depend on the specific application's needs: common locations are to local application data if it's to be edited only through the app (this is typical for databases and such) or to a user-chosen location if the data is to be edited external to the app (as in your case).

    Normally I would open a file picker to let the user choose where to put the data. Since you sound like you have an enterprise side-loading scenario where you may want to pre-define where the data is you could add restricted capabilities to put the data in the documents folder (similar to what Visual Studio does) or elsewhere with broadFileSystemAccess.

    Note that this follows best practices for desktop apps as well, which generally don't allow write access for normal users to their install directory and are recommended to put user data elsewhere. Click-once may be an exception since I think they're per-user installs, but I'm not deeply familiar with Click-once technical details. 

    Friday, December 7, 2018 5:54 PM
  • Do you have any links on this?


    Eric

    Friday, December 7, 2018 6:49 PM
  • I tried you approach with no luck. The sub below works perfectly when running local, but in Windows Store it fails with no error!

    About to give-up publishing apps to the store, not worth the effort and Microsoft Support and feaatures suck.

        Private Sub CopyDefaultTemplateFiles()
            Try

                Dim templatesPath As String = AppDomain.CurrentDomain.BaseDirectory
                templatesPath = Path.Combine(templatesPath, "Templates")

                If Directory.Exists(templatesPath) = False Then
                    Directory.CreateDirectory(templatesPath)
                End If

                Dim files As String() = Directory.GetFiles(templatesPath)

                ' copy template files to AppData\Roaming\FrozenElephant\SymbioticHelper\Templates\ folder
                For Each fitem As String In files
                    Dim fn As String = Path.GetFileName(fitem)
                    Dim f As String = My.Settings.TemplateFolder + "\" + fn

                    If File.Exists(f) = False Then
                        File.Copy(fitem, f)
                    End If

                Next

            Catch ex As Exception
                Dim fe As New FormError()
                fe.txtError.Text = ex.ToString()
                fe.ShowDialog()
            End Try
        End Sub


    Eric

    Thursday, June 6, 2019 7:37 PM
  • Your code is still editing the install directory and the location you're copying to doesn't look like the right place for UWP app data (as Roy mentioned, it'd be in ...\AppData\Local\Packages\<your package name>\...

    See https://docs.microsoft.com/en-us/windows/uwp/design/app-settings/store-and-retrieve-app-data#local-app-data for information about where UWP apps should keep local data.

    And here's a quick code snippet:

    Imports Windows
    Imports Windows.Storage
    
        Private Async Function CopyDefaultTemplateFiles() As Task(Of Boolean)
            ' Read only folder of templates shipped in the APPX
            Dim staticTemplates As StorageFolder = Await Package.Current.InstalledLocation.GetFolderAsync("Templates")
            Debug.WriteLine($"Installed templates: {staticTemplates.Path}")
            ' Create Or open writable Templates folder in user data
            Dim userTemplates As StorageFolder = Await ApplicationData.Current.LocalFolder.CreateFolderAsync("Templates", CreationCollisionOption.OpenIfExists)
            Debug.WriteLine($"User Editable templates: {userTemplates.Path}")
    
            ' Get files in the templates folder
            Dim files As IReadOnlyList(Of StorageFile) = Await staticTemplates.GetFilesAsync()
    
            ' Copy files to the userTemplates folder
            For Each fitem As StorageFile In files
                ' Copy the file to over. Leave it alone if it already exists
                Try
                    Await fitem.CopyAsync(userTemplates, CreationCollisionOption.OpenIfExists)
                Catch Ex As Exception
                    Debug.WriteLine($"Exception {Ex.Message} {fitem.Path}")
                End Try
            Next
            Return True
        End Function

    You could also use .Net file API instead of Windows.Storage API for these specific folders, but most other folders don't have unbrokered access.

    If you need one-on-one help with this you can open a support case at https://aka.ms/storesupport and choose Windows 10 UWP app development on the Contact us page.

    Thursday, June 6, 2019 9:03 PM
  • i'm not changing the install folder.

    I default the templates folder as below:

           Dim appfolder As String = Path.Combine(filepath, "FrozenElephant\SymbioticHelper")

            If Directory.Exists(appfolder) = False Then
                Directory.CreateDirectory(appfolder)
            End If

            My.Settings.TemplateFolder = Path.Combine(appfolder, "Templates")

    The frustrating thing is there is no way to test or debug things, such a crappy design.


    Eric

    Thursday, June 6, 2019 10:43 PM
  • This chunk of code will write to the install folder. I suspect you intended it to make sure the appfolder exists and not the template directory in the app package, and this probably doesn't cause a problem in your test environment because you have the templatesPath directory set up.

                If Directory.Exists(templatesPath) = False Then
                    Directory.CreateDirectory(templatesPath)
                End If

    You don't provide enough information to know where this writes to (what is 'filepath'), but it looks unlikely that this is a valid location for your app to store data. You need to query for the AppFolder location from ApplicationData.Current.LocalFolder or equivalent. 

    'Wrong, unless filepath came from something like ApplicationData.Current.LocalFolder
    Dim appfolder As String = Path.Combine(filepath, "FrozenElephant\SymbioticHelper")
    
    'Right. This will already be specific to the app package. No need to add your publisher and app name again
    Dim appfolder As String = ApplicationData.Current.LocalFolder.Path
    

    That said, this will put the templates in a location that isn't exposed to users. If you want them to be able to edit the templates you'll need to place it in user space. A picked folder is generally best, since users can then choose how to organize their system themselves. To do so it'll be easier to use the Windows.Storage API as in my code snippet rather than the System.IO.File classes, since the Windows.Storage classes will manage the permissions for you. Just change the target StorageFolder from ApplicationData.Current.LocalFolder to the one returned by the FolderPicker, and cache the result so it only needs to be chosen once.

    You can debug this by packaging the app and then attaching a debugger. The problem doesn't reproduce in your test environment because you're testing a different environment than you're installing to - this isn't UWP specific. For most things it doesn't matter and it's more efficient to build and debug the unpackaged application, but you can (and should) debug the actual target package before signing off as done.

    If you're still confused then I strongly recommend that you open a support case and somebody can work directly with you to make sure that you get and understand an appropriate solution for your actual scenario.

    --Rob

    Friday, June 7, 2019 12:18 AM
  •         Dim filepath As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

            Dim appfolder As String = Path.Combine(filepath, "FrozenElephant\SymbioticHelper")

    Eric

    Friday, June 7, 2019 12:26 AM
  • ok, how about Microsoft throw an exception and also enforce this during development?

    or better yet, support deploying editable app data like how it used to work!

    So frustrating, spend 20 years learning shit. the Microsoft changes everything so you have to ReLearn stupid shit again.


    Eric


    Friday, June 7, 2019 12:27 AM
  • i get the following error:

    Severity    Code    Description    Project    File    Line    Suppression State
    Error    BC30451    'ApplicationData' is not declared. It may be inaccessible due to its protection level.    SymbioticHelper    G:\Dev\FrozenElephant\SymbioticORM\Symbiotic\SymbioticHelper\FormCodeConfigure.vb    62    Active

    Note this is not a UWP app but a Windows Forms app.


    Eric

    Wednesday, June 12, 2019 3:25 PM
  • So what's wrong with this code?

        Private Sub CheckTemplatesFolder()

            Dim filepath As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)

            Dim appfolder As String = Path.Combine(filepath, "FrozenElephant\SymbioticHelper")

            If Directory.Exists(appfolder) = False Then
                Directory.CreateDirectory(appfolder)
            End If

            My.Settings.TemplateFolder = Path.Combine(appfolder, "Templates")

            If Directory.Exists(My.Settings.TemplateFolder) = False Then
                Directory.CreateDirectory(My.Settings.TemplateFolder)

                CopyDefaultTemplateFiles()
            Else
                Dim files() = Directory.GetFiles(My.Settings.TemplateFolder)

                If files.Length = 0 Then
                    CopyDefaultTemplateFiles()
                End If
            End If


        End Sub


    Eric

    Wednesday, June 12, 2019 5:30 PM
  • I cant find this contacts page or link, can you be more specific?

    Eric

    Friday, June 14, 2019 3:46 PM
  • That you're using a WinForms app (presumably) via Desktop Bridge and not creating a Windows Store app changes a few details. You should be running in full trust and have permissions to some areas that full UWP apps don't have access to by default, and several of the system folders used by desktop apps are shadowed so that they can be called from the packaged context.. Talking to somebody directly will help cut through the scenario details much more easily.

    On https://aka.ms/storesupport there is a "Contact us" link about half-way down:

    Contact us link on aka.ms/storesupport page

    After clicking that it'll expand out a form to tell what your issue is about. Select "Desktop Bridge" and then push "Submit an incident" to the right. The first few fields of the next form will be populated based on your initial selection. Set the category "Converted Desktop App Issues" and the problem "Runtime issues", then on the next page provide a free-text problem description explaining that you have a WinForms app you're packaging via the desktop bridge, how you're converting it, and that it's unable to write to Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)


    Friday, June 14, 2019 5:44 PM
  • Thanks Rob

    FYI the page does not work in FireFox browser, does a real nice endless loop trying to load the page.

    Was able to get it working on Microsoft's Edge browser.

    Also say I must pay, don't plant to pay for their problems or my free developer tool.

    https://www.microsoft.com/store/productId/9NN20Q6WFKGS

    Eric


    Eric

    Friday, June 14, 2019 7:59 PM
  • This fails even when app is ran as admin.

    Private Sub CheckTemplatesFolder()

            Dim filepath As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)

            Dim appfolder As String = Path.Combine(filepath, "FrozenElephant\SymbioticHelper")

            If Directory.Exists(appfolder) = False Then
                Directory.CreateDirectory(appfolder)
            End If

            My.Settings.TemplateFolder = Path.Combine(appfolder, "Templates")

            If Directory.Exists(My.Settings.TemplateFolder) = False Then
                Directory.CreateDirectory(My.Settings.TemplateFolder)

                CopyDefaultTemplateFiles()
            Else
                Dim files() = Directory.GetFiles(My.Settings.TemplateFolder)

                If files.Length = 0 Then
                    CopyDefaultTemplateFiles()
                End If
            End If


        End Sub

        Private Sub CopyDefaultTemplateFiles()
            Try

                Dim templatesPath As String = AppDomain.CurrentDomain.BaseDirectory
                templatesPath = Path.Combine(templatesPath, "Templates")

                If Directory.Exists(My.Settings.TemplateFolder) = False Then
                    Directory.CreateDirectory(My.Settings.TemplateFolder)
                End If

                Dim files As String() = Directory.GetFiles(templatesPath)

                ' copy template files to AppData\Roaming\FrozenElephant\SymbioticHelper\Templates\ folder
                For Each fitem As String In files
                    Dim fn As String = Path.GetFileName(fitem)
                    Dim f As String = My.Settings.TemplateFolder + "\" + fn

                    If File.Exists(f) = False Then
                        File.Copy(fitem, f)
                    End If

                Next

            Catch ex As Exception
                Dim fe As New FormError()
                fe.txtError.Text = ex.ToString()
                fe.ShowDialog()
            End Try
        End Sub



    Eric



    Tuesday, June 25, 2019 4:36 AM
  • Yep, Microsoft doesn't care about it's apps in the store, no wonder it's so bare...

    Eric

    Tuesday, June 25, 2019 4:38 AM
  • Hi,

    So it happens when you debug the converted app? Could you please tell me the error code or error message you get? In which way you are trying to convert your desktop app?

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 25, 2019 7:53 AM
    Moderator
  • I don't remember how it was converted, just that I did it as Microsoft asked years ago.

    lol, yea It would be nice to have an error. Maybe Microsoft could fix that. I even tried attaching to the deployed app debugging, I get nothing.

    Also work perfectly when debug mode prior to deployment.

    https://www.microsoft.com/store/productId/9NN20Q6WFKGS


    Eric


    Tuesday, June 25, 2019 1:15 PM
  • As previously discussed, I highly recommend that you open a support case for this. It's very difficult to determine what is going on in your app from the details you have provided. At this point, the actual symptom isn't even clear.

    A call where you can explain more clearly what you are doing and what problem you're seeing will allow us to help you. 

    Beyond that, my crystal ball says that the data is being written (hence no error), but that you're not looking in the right place for it. See 

    https://docs.microsoft.com/en-us/windows/msix/desktop/desktop-to-uwp-behind-the-scenes#file-system for more information on how desktop bridge applications shadow the AppData folder.

    Again, if you need more help then please open a support case and somebody can work with you directly.

    Tuesday, June 25, 2019 5:55 PM
  • as i stated, they want me to pay. That is to pay to solve a Microsoft problem.

    Also the code works during testing and with a MSI installer.

    And no the files are NOT copied.

        Private Sub CopyDefaultTemplateFiles()
            Try

                Dim templatesPath As String = AppDomain.CurrentDomain.BaseDirectory
                templatesPath = Path.Combine(templatesPath, "Templates")

                If Directory.Exists(My.Settings.TemplateFolder) = False Then
                    Directory.CreateDirectory(My.Settings.TemplateFolder)
                End If

                Dim files As String() = Directory.GetFiles(templatesPath)

                ' copy template files to AppData\Roaming\FrozenElephant\SymbioticHelper\Templates\ folder
                For Each fitem As String In files
                    Dim fn As String = Path.GetFileName(fitem)
                    Dim f As String = My.Settings.TemplateFolder + "\" + fn

                    If File.Exists(f) = False Then
                        File.Copy(fitem, f)
                    End If

                Next

            Catch ex As Exception
                Dim fe As New FormError()
                fe.txtError.Text = ex.ToString()
                fe.ShowDialog()
            End Try
        End Sub


    Eric

    Tuesday, June 25, 2019 6:58 PM
  • Hi,

    Have you checked the event log from the Event Viewer about the crash. Generally it will give the error message which could help to narrow down the problem. You could find the event log from Applications and Service Logs->Microsoft->Windows->Apps->Microsoft-Windows-TWinUI/Operational

    It looks like this:

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, June 26, 2019 4:38 AM
    Moderator
  • Ok, might help if the message actually makes sense...

    Oh, and the app is installed, just doesn't copy the files for the specified code and does not raise an error. Works fine in visual studio debugger.

    Thanks for the info though...

    Activation for 40329FrozenElephantInc.SymbioticCodeGenerator_59hzgejs1kvn0!App failed. Error code: This app does not support the contract specified or is not installed.. Activation phase: No phase defined


    Eric


    Wednesday, June 26, 2019 5:14 AM
  • I think this error is from me trying to attach the VS debugger to the installed app though...

    Eric

    Wednesday, June 26, 2019 5:19 AM