Click here to Skip to main content
15,888,579 members
Home / Discussions / C#
   

C#

 
Generalto get date, month, year from date seperately Pin
trilokharry28-Jan-08 19:16
trilokharry28-Jan-08 19:16 
GeneralCross post Pin
pmarfleet28-Jan-08 19:46
pmarfleet28-Jan-08 19:46 
GeneralRe: to get date, month, year from date seperately Pin
J a a n s28-Jan-08 20:18
professionalJ a a n s28-Jan-08 20:18 
GeneralRe: to get date, month, year from date seperately Pin
Nouman Bhatti28-Jan-08 20:47
Nouman Bhatti28-Jan-08 20:47 
QuestionWord.Comments colelction Pin
PS@Codeproj28-Jan-08 17:06
PS@Codeproj28-Jan-08 17:06 
GeneralRe: Word.Comments colelction Pin
Skippums28-Jan-08 17:39
Skippums28-Jan-08 17:39 
QuestionRe: Word.Comments colelction Pin
fantasy121529-Jan-08 2:31
fantasy121529-Jan-08 2:31 
GeneralRe: Word.Comments colelction Pin
Skippums29-Jan-08 7:40
Skippums29-Jan-08 7:40 
I made a class WordInstance as follows, that instantiates and hides a word instance...
...
using Word = Microsoft.Office.Interop.Word;
...
public class WordInstance : IDisposable {
    private const string WORD_APPLICATION_EXE = "WINWORD.EXE";
    ...
    private static readonly object s_Lock = new object();
    private Word.Application m_WordApp = null;
    ...
    public WordInstance() {
        try {
            int attempt = 0;
            do {
                IList<IntPtr> allWordWinsPrior, allWordWinsAfter;
                lock (s_Lock) {
                    // Get handles to all open instances of Word
                    allWordWinsPrior = WinAPI.GetAllRootWindowsOfClass("OpusApp");
                    // Create two instances of Word, then close the first
                    // MS has a release stating that this methodology will fix
                    // the problem that opening a new instance of Word will
                    // simply use this instance instead of creating a new one.
                    Word.Application temp = new Word.Application();
                    m_WordApp = new Word.Application();
                    temp.Quit(ref s_QuitNoSave, ref s_QuitEmpty, ref s_QuitEmpty);
                    m_WordApp.DocumentOpen += new Microsoft.Office.Interop.Word
                        .ApplicationEvents4_DocumentOpenEventHandler(m_WordApp_DocumentOpen);
                    // Get handles to all open instances of Word
                    allWordWinsAfter = WinAPI.GetAllRootWindowsOfClass("OpusApp");
                }
                foreach (IntPtr ptr in allWordWinsPrior)
                    allWordWinsAfter.Remove(ptr);
                if (allWordWinsAfter.Count > 1) {
                    for (int i = allWordWinsAfter.Count - 1; i >= 0; --i)
                        if (WinAPI.IsWindowVisible(allWordWinsAfter[i]))
                            allWordWinsAfter.RemoveAt(i);
                }
                if (allWordWinsAfter.Count > 0) {
                    m_Handle = allWordWinsAfter[0];
                    return;
                }
            } while (++attempt < 3);
            throw new Exception();
        } catch {
            Dispose();
        }
    }
    ...
    public void Dispose() {
        if (m_WordApp != null) {
            try {
                // Try to quit word normally
                if (m_WordApp.Documents.Count > 0)
                    m_WordApp.Documents.Close(ref s_QuitNoSave, ref s_QuitEmpty, ref s_QuitEmpty);
                m_WordApp.Quit(ref s_QuitNoSave, ref s_QuitEmpty, ref s_QuitEmpty);
            } catch {
                // If the above fails, force word to quit
                if (m_Handle != IntPtr.Zero)
                    WinAPI.DestroyWindow(m_Handle);
            }
            m_WordApp = null;
            m_Handle = IntPtr.Zero;
        }
    }
    ...
    // Event Handler
    private void m_WordApp_DocumentOpen(Word.Document Doc) {
        if (m_WordApp == null)
            return;
        WinAPI.ShowWindow(m_Handle, (uint)WinAPI.SW.HIDE);
        string documentName = Doc.Name;
        string documentFullName = Doc.FullName;

        /*
         * Close document and re-open in new (different) instance of MS Word application 
         * (since we don't want to "share" an instance with a user while they interactively
         * use Word or with any other processing)
         */
        Doc.Close(ref s_QuitNoSave, ref s_QuitEmpty, ref s_QuitEmpty);
        if (documentFullName.Equals(documentName))
            openDocInNewWordInstance(null);
        else
            openDocInNewWordInstance(documentFullName);
    }
    ...
    // Called from the event handler
    private void openDocInNewWordInstance(string pathFileName) {
        ProcessStartInfo wordStartInfo = new ProcessStartInfo(WORD_APPLICATION_EXE);
        wordStartInfo.UseShellExecute = true;
        wordStartInfo.Arguments = (string.IsNullOrEmpty(pathFileName)
            ? "/w" : string.Format("/w \"{0}\"", pathFileName));
        wordStartInfo.WindowStyle = ProcessWindowStyle.Normal;
        Process.Start(wordStartInfo);
    }
}
After instantiating word, use the word API to save the file in the xml doc format. Then close word, load the doc and parse the xml. You will need to become familiar with some WinAPI functions along with the Word API. Good luck.

Sounds like somebody's got a case of the Mondays

-Jeff

QuestionHow to Set a Windows service for a particular domain user Pin
Narendra Mohan28-Jan-08 17:02
Narendra Mohan28-Jan-08 17:02 
AnswerRe: How to Set a Windows service for a particular domain user Pin
Abhijit Jana28-Jan-08 17:47
professionalAbhijit Jana28-Jan-08 17:47 
Generalasdfadsf Pin
Member 462175228-Jan-08 14:01
Member 462175228-Jan-08 14:01 
GeneralRe: asdfadsf Pin
Member 462175228-Jan-08 14:04
Member 462175228-Jan-08 14:04 
GeneralRe: asdfadsf Pin
Colin Angus Mackay29-Jan-08 0:18
Colin Angus Mackay29-Jan-08 0:18 
GeneralPerformance : String and string !! Confusing, Pin
Nadia Monalisa28-Jan-08 13:26
Nadia Monalisa28-Jan-08 13:26 
GeneralRe: Performance : String and string !! Confusing, Pin
PIEBALDconsult28-Jan-08 13:45
mvePIEBALDconsult28-Jan-08 13:45 
GeneralRe: Performance : String and string !! Confusing, Pin
Paul Conrad28-Jan-08 14:06
professionalPaul Conrad28-Jan-08 14:06 
GeneralRe: Performance : String and string !! Confusing, Pin
Scott Dorman28-Jan-08 17:49
professionalScott Dorman28-Jan-08 17:49 
GeneralRe: Performance : String and string !! Confusing, Pin
Mohan Kumar28-Jan-08 20:26
Mohan Kumar28-Jan-08 20:26 
GeneralRe: Performance : String and string !! Confusing, Pin
Guffa28-Jan-08 20:47
Guffa28-Jan-08 20:47 
GeneralRe: Performance : String and string !! Confusing, Pin
leppie28-Jan-08 21:44
leppie28-Jan-08 21:44 
GeneralRe: Performance : String and string !! Confusing, Pin
Skippums29-Jan-08 7:49
Skippums29-Jan-08 7:49 
GeneralRe: Performance : String and string !! Confusing, Pin
PIEBALDconsult29-Jan-08 8:39
mvePIEBALDconsult29-Jan-08 8:39 
GeneralRe: Performance : String and string !! Confusing, Pin
Skippums29-Jan-08 8:47
Skippums29-Jan-08 8:47 
GeneralRe: Performance : String and string !! Confusing, Pin
PIEBALDconsult29-Jan-08 12:22
mvePIEBALDconsult29-Jan-08 12:22 
GeneralProcess not ending when application is closed. Pin
Ylno28-Jan-08 13:01
Ylno28-Jan-08 13:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.