locked
In WinRT, What are the DocumentProperties Parameters?

    Question

  • I am trying to change the DocumentProperties.Keywords.IsReadOnly parameter of a txt file I created to True.

    I can see it, I can Get it, but I can not fine a way to Set it.

    I have been trying to use file.Properties.SavePropertiesAsync, but  I keep getting "The paramater is incorrect" exception.

    I have tried "IsReadOnly"

    Keywords.IsReadOnly

    DocumentProperties.Keywords.IsReadOnly

    I tried RetrievePropertiesAsync to get a list but it wants a parameter as well. So apparently you need to know what the parameters are before you can get them.

    I can not fine a list of parameters documented anywhere.

    Any Pointers?

    Eric

    Friday, November 2, 2012 9:43 PM

Answers

  • Just to followup, in case you want to set the "readonly" (actually it's from the "System.FileAttributes" property), you can use the following code:

    function changeFileProperties() {
            
            Windows.Storage.KnownFolders.picturesLibrary.getFileAsync("test.jpg").then(
                function (file) {
    
                   
                    var propSet = new Windows.Foundation.Collections.PropertySet();
                    //propSet.insert("System.FileAttributes", 32);  // REMOVE READONLY
                    propSet.insert("System.FileAttributes", 33);    // SET TO READONLY
    
                    file.properties.savePropertiesAsync(propSet).done(function (setProp) {
                        console.log("SAve properties");
                    });
                },
                function (err) {
                    console.log("Error, open File Async");
                }
            );
        }
    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. Putting communities in your palms. Launch the browser on your phone now, type aka.ms/msforums and get connected!

    • Marked as answer by E Schlosser Tuesday, November 6, 2012 5:32 PM
    Monday, November 5, 2012 9:26 AM
    Moderator
  • Thank You Steve, That was it!

    Final code was...

    public async void changeFileProperties(StorageFile file )

    {

        try

        {

                     List<KeyValuPair<string, Object>> readOnlyProperty= new List<KeyValuPair<string, Object>>();

                     readOnlyProperty.Add(new KeyValuPair<string, Object>(System.FileAttributes",33));

                    Await File.Properties.SavePropertiesAsync(readOnlyProperty);

            }

             catch (Exception err)

        {

             console.writeLine("Error")

        }

    }

    • Marked as answer by E Schlosser Tuesday, November 6, 2012 5:32 PM
    Tuesday, November 6, 2012 5:32 PM

All replies

  • Hello,

    You can take a look at the "File Access sample" in the SDK: http://code.msdn.microsoft.com/windowsapps/File-access-sample-d723e597 that shows how to list the different properties of a file. In that sample you will notice how to list the File Owner and the Date Accessed properties. Hopefully that should get you going.

    Thanks,

    Prashant.

    Friday, November 2, 2012 11:33 PM
    Moderator
  • Hi Eric,

    For the file properties, you can supply an empty list/array when calling the "retrievePropertiesAsync" method so that you can enumerate all the properties available (see sample code below). However, there are many properties that are read-only, so you might not be able to modify them via savePropertiesAsync.

    Windows.Storage.KnownFolders.picturesLibrary.getFileAsync("test.png").then(
                function (file) {                
                    var propKeys = [];
                    file.properties.retrievePropertiesAsync(propKeys).then(
                        function (props) {
    
                            var prop = props.first();
    
                            do {
                                console.log(prop.current.key + ": " + prop.current.value);
                            } while (prop.moveNext());
                        },
                        function (errProps) {
                            console.log("Error, retriving document properties");
                        }
                    );
                  
                },
                function (err) {
                    console.log("Error, File is not got.");
                }
            );

    Please remember to mark the replies as answers if they help and unmark them if they provide no help. Putting communities in your palms. Launch the browser on your phone now, type aka.ms/msforums and get connected!

    Monday, November 5, 2012 8:43 AM
    Moderator
  • Just to followup, in case you want to set the "readonly" (actually it's from the "System.FileAttributes" property), you can use the following code:

    function changeFileProperties() {
            
            Windows.Storage.KnownFolders.picturesLibrary.getFileAsync("test.jpg").then(
                function (file) {
    
                   
                    var propSet = new Windows.Foundation.Collections.PropertySet();
                    //propSet.insert("System.FileAttributes", 32);  // REMOVE READONLY
                    propSet.insert("System.FileAttributes", 33);    // SET TO READONLY
    
                    file.properties.savePropertiesAsync(propSet).done(function (setProp) {
                        console.log("SAve properties");
                    });
                },
                function (err) {
                    console.log("Error, open File Async");
                }
            );
        }
    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. Putting communities in your palms. Launch the browser on your phone now, type aka.ms/msforums and get connected!

    • Marked as answer by E Schlosser Tuesday, November 6, 2012 5:32 PM
    Monday, November 5, 2012 9:26 AM
    Moderator
  • Steve, Thank you for your reply but I am still having problems. frst,

    Asumption: the above code is written in javascript.

    I rewrote it in c# and it looks like this...

    public async void changeFileProperties(StorageFile file )

    {

        try

        {

            var propSet = new Windows.Foundation.Collections.PropertySet();

            propSet.Add("System.FileAttributes", 33); // SET TO READONLY

            await file.Properties.SavePropertiesAsync(propSet);

        }

        catch (Exception err)

        {

            console.write("Error")          

        }

    }

    I still get the same Execption thrown "The paramater is incorrect".

    I must be missing something,

    Eric

    Monday, November 5, 2012 6:43 PM
  • Thanks for your reply Eric,

    I assume that you're using HTML/JS :)

    For C#, it is possible that the coding syntax is different.  I use PropertySet since that's the one I can make the function work in javascript. If you use c#, you can directly create a List<KeyValuePair<string, object>>   to hold all the properties you want to save (see the following thread):

    http://social.msdn.microsoft.com/Forums/en-AU/winappswithcsharp/thread/aaf0b373-b0e0-4d91-84d8-69e768a374d8


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. Putting communities in your palms. Launch the browser on your phone now, type aka.ms/msforums and get connected!

    • Marked as answer by E Schlosser Tuesday, November 6, 2012 5:32 PM
    • Unmarked as answer by E Schlosser Tuesday, November 6, 2012 5:32 PM
    Tuesday, November 6, 2012 2:39 AM
    Moderator
  • Thank You Steve, That was it!

    Final code was...

    public async void changeFileProperties(StorageFile file )

    {

        try

        {

                     List<KeyValuPair<string, Object>> readOnlyProperty= new List<KeyValuPair<string, Object>>();

                     readOnlyProperty.Add(new KeyValuPair<string, Object>(System.FileAttributes",33));

                    Await File.Properties.SavePropertiesAsync(readOnlyProperty);

            }

             catch (Exception err)

        {

             console.writeLine("Error")

        }

    }

    • Marked as answer by E Schlosser Tuesday, November 6, 2012 5:32 PM
    Tuesday, November 6, 2012 5:32 PM