none
It is possible to replace an opened powerpoint 2013 file using File.WriteAllBytes C# code in Window 8.1 RRS feed

  • Question

  • Hi,

    I am facing an issue with Office 2013 powerpoint file. I have opened a powerpoint file. Through C# code, i am trying to replace the opened powerpoint file using the code File.WriteAllBytes(path, System.Convert.FromBase64String(base64String));

    The expected result is that we should get an error message that the file is being used by a process. But here the opened file gets replaced by the code and it is the issue. I'm working on Windows 8.1 system.

    The issue does not occur with word and excel file.

    Can anyone please help me on this.

    Monday, May 12, 2014 9:00 AM

Answers

  • Hi ShanavasP,

    >> The expected result is that we should get an error message that the file is being used by a process

    The file is opened by Power Point Process in Share Mode. You could use the code below to check whether is opened by another process.

            private static bool IsFileOpen(string path)
            {
                bool isOpen = false;
    
                FileStream stream = null;
    
                try
                {
                    stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None);
                }
                catch (IOException)
                {
                    isOpen = true;
                }
                finally
                {
                    if (stream != null)
                    {
                        stream.Close();
                    }
                }
    
                return isOpen;
            }


    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.

    Tuesday, May 13, 2014 8:08 AM
    Moderator

All replies

  • Hello,

    What code do you use for opening the file? Why do you expect to get an error message box?

    What exactly do you want to implement? Be aware, you can use Open XML SDK for Office for working with documents without Office applications involved.

    Monday, May 12, 2014 10:30 AM
  • Hi,

    I am trying a create a powerpoint file in specific location. but it is doing by openfiledialogue. So here i'm trying a replace an existing opened file. In that case it shall not replace the exisiting opened file. So i'm expecting a message for that. But here it is replacing the opened file which may not occur.

    I am trying to create a file using File.WriteAllBytes(path, System.Convert.FromBase64String(base64String));

    How can i solve this issue?

    Monday, May 12, 2014 12:05 PM
  • Hi ShanavasP,

    >> The expected result is that we should get an error message that the file is being used by a process

    The file is opened by Power Point Process in Share Mode. You could use the code below to check whether is opened by another process.

            private static bool IsFileOpen(string path)
            {
                bool isOpen = false;
    
                FileStream stream = null;
    
                try
                {
                    stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None);
                }
                catch (IOException)
                {
                    isOpen = true;
                }
                finally
                {
                    if (stream != null)
                    {
                        stream.Close();
                    }
                }
    
                return isOpen;
            }


    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.

    Tuesday, May 13, 2014 8:08 AM
    Moderator