Sayfalar

Translate Blog

ProcessStartInfo etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
ProcessStartInfo etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

19 Nisan 2013 Cuma

C# Word Belgesi Açmak / Open Office Word Documents

Eğer c# ile office belgelerini açmak istiyorsanız aşağıdaki gibi bir kod kullanmalısınız. Using satırına System.Diagnostics eklemelisiniz. Aksi halde ProcessStartInfo kodu çalışmayacaktır.
Belgenizi açacağınız programın yolunu çift slashlı (//) olarak yazmalı, belgenizin adını seçmeli ve hangi dizinde olduğunu (@"C:\";) da belirlemelisiniz. Bu kodda butona tıklandığında açılan bir a.docx belgesinin örneğidir. 32 veya 64 bitlik bilgisayarlarda Program Files değişmektedir, kalınızda olsun.

If you want to open any document with any program, you should use ProcessStartInfo on c#.
You can use these codes for open word file. Other file types has the same way. Show the main program way  as FileName, and your file that wanted to open as Arguments. This sample show "open a.docx file on C:/ when you click button".


using System.Diagnostics;
using System.IO; //for File.Exist() command

private void button1_Click(object sender, EventArgs e)
        {         
           ProcessStartInfo startInfo = new ProcessStartInfo();
            //32 Bits
            //startInfo.FileName = "C:\\Program Files\\Microsoft Office\\Office12\\WINWORD.EXE";

            //64 bits
            startInfo.FileName = "C:\\Program Files (x86)\\Microsoft Office\\Office12\\WINWORD.EXE";
            startInfo.Arguments = "a.docx";
            startInfo.WorkingDirectory = @"C:\";
            startInfo.WindowStyle = ProcessWindowStyle.Maximized;
            if (File.Exists(startInfo.WorkingDirectory + startInfo.Arguments))
            {
                Process process = Process.Start(startInfo);
            }
            else
            {
                MessageBox.Show("Belge Yok");
            }