none
What may corrupt The file C:\Users\XXX\AppData\Local\Microsoft\Outlook\Outlook.pst file while automating outlook

    Question

  • Hi,

    C:\Users\XXX\AppData\Local\Microsoft\Outlook\Outlook.pst  file is being corrupted while programatically printing outlook emails. after printing couple of emails it is being corrupt and I need to delete this file and recreate a new one everytime.

       at Microsoft.Office.Interop.Outlook.NameSpaceClass.GetDefaultFolder(OlDefaultFolders FolderType)

    Thanks,

    Bibek Dawadi

    Friday, October 22, 2010 5:31 PM

Answers

  • OK, I'm not sure about the corruption, that may be because you aren't releasing your Outlook objects. You can do that by handling the Application.Quit() event and when that fires you can release everything.

    The reason Outlook is closing is that it was opened with no user interface. So as soon as its only window is closed (the Inspector) it exits. You can prevent that by creating UI (using MAPIFolder.GetExplorer() to instantiate an Outlook Explorer object.

    I'd recommend logging into Outlook's NameSpace object however, especially as you are automating Outlook from standalone code. You can use _outlookNameSpace.Logon("", "", false, false) as your logon line just after you instantiate the NameSpace object.


    Ken Slovak MVP - Outlook
    • Marked as answer by Bessie Zhao Monday, November 01, 2010 9:30 AM
    Thursday, October 28, 2010 8:03 PM
    Moderator

All replies

  • No way to tell with the information you've supplied.
     
    What version of Outlook?
     
    How are you doing the printing? Show your code for that.
     
    Are you seeing any exceptions?
     
    Is Outlook crashing?
     
    Are any events being logged for crashes or hangs?
     
    How do you know the PST is corrupted?
     
    What does GetDefaultFolder() have to do with this, and what folder are you trying to retrieve? Are you trying to retrieve a type that isn't there with a PST such as Exchange Public Folders?

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007.
    Reminder Manager, Extended Reminders, Attachment Options.
    http://www.slovaktech.com/products.htm
     
     
    "Bibek Dawadi" <=?utf-8?B?QmliZWsgRGF3YWRp?=> wrote in message news:3aebf701-88a7-4279-b879-c19646b5dc3a...

    Hi,

    C:\Users\XXX\AppData\Local\Microsoft\Outlook\Outlook.pst  file is being corrupted while programatically printing outlook emails. after printing couple of emails it is being corrupt and I need to delete this file and recreate a new one everytime.

       at Microsoft.Office.Interop.Outlook.NameSpaceClass.GetDefaultFolder(OlDefaultFolders FolderType)

    Thanks,

    Bibek Dawadi


    Ken Slovak MVP - Outlook
    Friday, October 22, 2010 8:47 PM
    Moderator
  • Hi Ken,

     I am getting following exception while Initializing the outlook but outlook is not crashing.

    Errors have been detected in the file. C:\Users\XXX\AppData\Local\Microsoft\Outlook\Outlook.pst. Quit Outlook and all mail-enabled applications, and then use the Inbox repair tool (Scanpst.exe) to diagnose and repair errors in the file. For more information about the Inbox repair tool, see Help"

    After getting this error, if I run Scanpst it will work for first few documents and starts throwing this error again. Even after deleting and recreating the Outlook.pst file didn't solve this problem.

    I am using Outlook 2007 on Windows 7.

    My code flow is  as below:

    - Initialize OutlookApplication

    - Initialize OutlookaNamespace

    - Get the outlookItem via  OutlookApplication.CreateItemFromTemplate

    - Call print method on outlook item

    - Close item (close item is quitting the outlookapplication because of which I have to reinitialize outlookapplication for each email I am printing.)

    Thanks in advance.

     

    regards,

    Bibek

     

    Monday, October 25, 2010 7:48 PM
  • Something you are doing is corrupting that PST file. I have no idea what. You didn't show your code, you just showed a flow list. So I have no idea what you are doing to corrupt the PST file.
     
    If closing an item is closing Outlook.Application then you are doing something wrong unless you are explicitly calling Application.Quit() or something like that.

    --
    Ken Slovak
    [MVP - Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007.
    Reminder Manager, Extended Reminders, Attachment Options.
    http://www.slovaktech.com/products.htm
     
     
    "Bibek Dawadi" <=?utf-8?B?QmliZWsgRGF3YWRp?=> wrote in message news:e13e8354-0317-4ce9-85ea-a6c31eaf64a6...

    Hi Ken,

     I am getting following exception while Initializing the outlook but outlook is not crashing.

    Errors have been detected in the file. C:\Users\XXX\AppData\Local\Microsoft\Outlook\Outlook.pst. Quit Outlook and all mail-enabled applications, and then use the Inbox repair tool (Scanpst.exe) to diagnose and repair errors in the file. For more information about the Inbox repair tool, see Help"

    After getting this error, if I run Scanpst it will work for first few documents and starts throwing this error again. Even after deleting and recreating the Outlook.pst file didn't solve this problem.

    I am using Outlook 2007 on Windows 7.

    My code flow is  as below:

    - Initialize OutlookApplication

    - Initialize OutlookaNamespace

    - Get the outlookItem via  OutlookApplication.CreateItemFromTemplate

    - Call print method on outlook item

    - Close item (close item is quitting the outlookapplication because of which I have to reinitialize outlookapplication for each email I am printing.)

    Thanks in advance.

     

    regards,

    Bibek

     


    Ken Slovak MVP - Outlook
    Tuesday, October 26, 2010 1:40 PM
    Moderator
  • Hi Ken,

    I am using the following code to open and print mailItem :

     private Microsoft.Office.Interop.Outlook.Application _outlookApplication = null;
    
    public Microsoft.Office.Interop.Outlook.Application OutlookApplication
    {
    	get
        {
        	if (_outlookApplication == null)
            {
             
            	_outlookApplication = new Microsoft.Office.Interop.Outlook.Application();            
             
            }
            return _outlookApplication;
    	}
        set { _outlookApplication = value; }
    }
    
    private static Microsoft.Office.Interop.Outlook.NameSpace _outlookNameSpace = null;
    
    public static Microsoft.Office.Interop.Outlook.NameSpace OutlookNameSpace
    {
    	get
        {
        	if (_outlookNameSpace == null)
            {          
              _outlookNameSpace = OutlookApplication.GetNamespace("MAPI");          
            }
            return _outlookNameSpace;
        }
          set { _outlookNameSpace = value; }
    }
    
    
    Folder draftsFolder = (Folder)Helper.OutlookNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderDrafts);
    
    object outlookItem = draftsFolder.Items.Add(OlItemType.olPostItem);
    
    if (outlookItem is MailItem)
    {
    	MailItem item = (MailItem)outlookItem;
    
    	item.PrintOut();
    
    
    	item.Close(OlInspectorClose.olDiscard); // this statement is closing the outlookapplication iteself and I need to re-initialize outlookapplication before printing another mailitem.
              
    }
    
    

    let me know if I am doing anything wrong here.

    regards,

     

    Bibek

    Wednesday, October 27, 2010 7:37 PM
  • OK, I'm not sure about the corruption, that may be because you aren't releasing your Outlook objects. You can do that by handling the Application.Quit() event and when that fires you can release everything.

    The reason Outlook is closing is that it was opened with no user interface. So as soon as its only window is closed (the Inspector) it exits. You can prevent that by creating UI (using MAPIFolder.GetExplorer() to instantiate an Outlook Explorer object.

    I'd recommend logging into Outlook's NameSpace object however, especially as you are automating Outlook from standalone code. You can use _outlookNameSpace.Logon("", "", false, false) as your logon line just after you instantiate the NameSpace object.


    Ken Slovak MVP - Outlook
    • Marked as answer by Bessie Zhao Monday, November 01, 2010 9:30 AM
    Thursday, October 28, 2010 8:03 PM
    Moderator
  • hi folks. I have also heard about

    .pst repair tools

    Friday, July 29, 2011 11:26 AM
  • Repair corrupted outlook file with the help of http://www.outlook.fixtoolbox.com

    utility must help you to restore any .pst file including of more than 2GB

    Thursday, June 07, 2012 6:54 PM