Answered How to write file using WriteFile in Metro apps?

  • Friday, April 13, 2012 4:07 AM
     
     

    Could I be authorized to write file in Metro Apps using Win32 API "WriteFile"(It should be used in Metro Apps according to the MSDN 's description)?

    if it did,how to get the absolute path of the file which is in document library(yes , i know the file must be here and i have to declare something in manifest at first)?

All Replies

  • Friday, April 13, 2012 8:50 AM
    Moderator
     
     

    Hello,

    First, I suggest you to follow up this sample codes
    http://code.msdn.microsoft.com/windowsapps/File-access-sample-d723e597

    You need to set the manifest.

    To enable access the document folder:
    Double click the Package.appxmanifest->Capabilites->Select Documents Library

    http://msdn.microsoft.com/en-us/library/windows/apps/hh465045.aspx
    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

  • Friday, April 13, 2012 3:06 PM
    Moderator
     
     

    Hi Cybupt,

    No, you cannot use WriteFile (or other Win32 file functions) for files in the Documents library. Your app does not have access to that location and cannot read or write from it directly. The app can directly access only the locations natively accessible to the app: files and folders within the app's local storage and install dir.

    Access to other locations such as the Documents Library is provided via a broker process. If your app has the appropriate capabilities and declarations (Document Library capability and file type association for files in the Documents Library) then it can request these files through the WinRT StorageFile and StorageFolder classes. The broker process will then open the files on your behalf and provide a stream with their contents.

    Using files: accessing, searching, and acting on files should give more details on how this works.

    --Rob

  • Saturday, April 14, 2012 12:32 AM
     
     

    Thanks

    Howerver,why can't I open the file in app dir with writing right using writefile api? And what would the correcting paramters be passed in writingfile api?

  • Saturday, April 14, 2012 3:48 AM
     
     
    Only read acces to app InstalledLocation (APPX) and R/W access to App's Data Path

    C++ DX11

  • Monday, April 16, 2012 1:40 AM
     
     
    And how can I get the path of APPX which would be passed into writefile api as parameter? 
  • Monday, April 16, 2012 2:26 AM
    Moderator
     
     Answered

    See Managing application data and the Application data sample.

    What is your specific use case here? If you explain what you want to do then we can provide better suggestions.

    Is there a reason you want to use WriteFile instead of Windows.Storage? While you can use CreateFile2/WriteFile, it's not generally going to be easier than or as powerful as using the Windows Runtime classes.

    --Rob

  • Monday, April 16, 2012 3:16 AM
     
     

    Some legacy lib need to be ported to WinRT, and they do not support multithread operation.


    C++ DX11

  • Monday, April 16, 2012 3:17 AM
     
     
    IStorageItem.Path is what you need.

    C++ DX11