locked
Open a file twice

    Question

  • Hi,

    I have opened a file using OpenAsync and got IRandomAccessStream, and modified that stream.

    Now I wanna open same file again and it must open with the original stream.

    How can I do?

    when I try to open same file again the application crashes!

    Thanx in advance

    _Sujith

    Monday, December 31, 2012 7:58 AM

Answers

All replies


  • Hi,

    Do you use try-catch block to get the exception?
    Like this

                create_task(file->OpenTransactedWriteAsync()).then([this, file, userContent](task<StorageStreamTransaction^> task)
                {
                    try
                    {
                        StorageStreamTransaction^ transaction = task.get();
                     }
                    catch(COMException^ ex)
                    {
                        rootPage->HandleFileNotFoundException(ex);
                    }
                });

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, January 1, 2013 8:10 AM
  • In addition solution, we can use IRandomAccessStream.CloneStream function to access the clone stream
    http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.streams.irandomaccessstream.clonestreaM

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by _Sujith Thursday, January 24, 2013 3:16 AM
    Friday, January 4, 2013 1:46 AM
  • What do you mean by "it must open with the original stream"?

    If you need to reuse the original stream then keep a reference and Seek to the beginning instead of reopening it.

    If you need to open a new stream the delete the original to force it to be closed (this is a general best practice). See the File Access sample for an example.

    If you need more help with this please provide a minimal code snippet which demonstrates the problem, clear repro steps, and a detailed description of the expected behavior and how that conflicts with the actual behavior.

    --Rob

    Friday, January 4, 2013 3:53 AM
    Owner