locked
Using SavePropertiesAsync RRS feed

  • Question

  • I am writing a file toucher which amends the file creation date of a scanned in jpg file and also renames it. I have based the app on the file picker sample in c++. I am new to metro and I do not know how to initialise the IkeyValuePair parameter to pass to SavePropertiesAsync()

    I have tried

    task<BasicProperties^> getBasicPropertiesTask(file->GetBasicPropertiesAsync());
    return getBasicPropertiesTask.then([=](BasicProperties^ stateFileProperties)
    {
    	typedef Windows::Foundation::Collections::IKeyValuePair<Platform::String^, Platform::Object^> KVPair;
    
    	auto size = unsigned int(stateFileProperties->Size);
    	auto itemdate = stateFileProperties->ItemDate;
    	auto datemodified = stateFileProperties->DateModified;
    	try
    	{
    	    auto propertyToSave = new IKeyValuePair<Platform::String^, Platform::Object^>();
    	    stateFileProperties.SavePropertiesAsync(propertyToSave);
    	}
    	catch (Platform::Exception^)
    	{
    	}
    						
    });
    
    

    But I get a warning for the creation of IKeyValuePair.

    Can you furnish me with the correct syntax please.

    Thanks MikeBr47

    Sunday, March 3, 2013 5:02 PM

Answers

  • Hello,

    You can use the below code to set properties in general. However, you cannot modify the DateCreated property (System.DateCreated) since it is read-only. See this link for more information: http://msdn.microsoft.com/en-us/library/windows/apps/br227171.aspx.

    If you were trying to set properties for an image, such as LensManufacturer or a CameraManufacturer, then you could use the below code:

    create_task(file->GetBasicPropertiesAsync()).then([this](BasicProperties^ stateFileProperties){
         auto size = unsigned int(stateFileProperties->Size);
         auto itemdate = stateFileProperties->ItemDate;
         auto datemodified = stateFileProperties->DateModified;
         try
         {
          PropertySet^ ps = ref new PropertySet();
          ps->Insert("System.Photo.LensManufacturer", ref new String(L"the greatest lens manufacturer"));
          ps->Insert("System.Photo.CameraManufacturer", ref new String(L"the greatest camera manufacturer"));
          stateFileProperties->SavePropertiesAsync(ps);
         }
         catch (Platform::Exception^)
         {
         }
        });

    Thanks,

    Prashant.

    Tuesday, March 5, 2013 12:36 AM
    Moderator