none
System.IO.IOException : The process can not access the file **** because it is being used by another process. RRS feed

  • Question

  • Hi,

    I have developed a Powerpoint Addin. when i want to add file in the presentation pptx file, I get an exception at :

    Package package = Package.Open(packagePath, FileMode.Create) : System.IO.IOException : The process can not access the file **** because it is being used by another process.

    Any one can help me how to solve this ?

    Thank you so much.

    Best regards.

    • Moved by George Hua Friday, May 30, 2014 7:41 AM .NET Framework class related
    Thursday, May 29, 2014 5:36 PM

Answers

  • Hi,

    Thank you for your reply, but when a file is opened with powerpoint, it is impossible to open the file in writing mode with an addIn.

    I think it is a negative thing that microsoft has to solve ...

    • Marked as answer by kbezzine Monday, June 9, 2014 8:54 AM
    Monday, June 9, 2014 8:52 AM

All replies

  • It seems you need to pass FileMode.OpenOrCreate instead of FileMode.Create .
    Thursday, May 29, 2014 5:52 PM
  • Hi,

    Since the question is more related to System.IO.Packaging, I have moved the thread to .NET Framework Class Libraries for more effective responses.

    Thanks for your understanding.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, May 30, 2014 7:42 AM
  • Hi Kbezzine,

    From your description, the packagePath file was opened by other process, so you cannot open it. Try closing the file to ignore the exception.

    If the file opened by you, I think you should use FileStream to open it. Code looks like the following.

    using (FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
    
                {
    
                   //.....
    
                }
    

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, May 30, 2014 7:59 AM
    Moderator
  • Hi, 

    The FileMode.OpenOrCreate option, doese not solve this problem ...

    Friday, May 30, 2014 10:55 AM
  • Hi,

    The file is opened by powerpoint, and my application is a powerpoint addin, so i can get a Presentation object but not a FileStream...

    Thank you.

    Friday, May 30, 2014 11:00 AM
  • Hi Kbezzine,

    Try to use Package.Open (String, FileMode, FileAccess, FileShare) method to share read and write. Code looks like:

    using (Package package = Package.Open("", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite))
                {
    
                }

    http://msdn.microsoft.com/en-us/library/ms568187(v=vs.110).aspx.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, June 4, 2014 2:28 AM
    Moderator
  • Hi,

    Thank you for your reply, but when a file is opened with powerpoint, it is impossible to open the file in writing mode with an addIn.

    I think it is a negative thing that microsoft has to solve ...

    • Marked as answer by kbezzine Monday, June 9, 2014 8:54 AM
    Monday, June 9, 2014 8:52 AM