อ่านไฟล์ PST/OST ที่เสียหาย

การจัดการไฟล์ที่เก็บข้อมูลเสียหาย

บางครั้งอาจไม่สามารถอ่านไฟล์ PST/OST ได้เนื่องจากปัญหาบางอย่าง เช่น บล็อกข้อมูลบางส่วนอาจเสียหาย ในกรณีเหล่านั้นข้อยกเว้นมักจะเกิดขึ้นเมื่อตัวเรียก the EnumerateFolders, EnumerateMessages, GetContents, GetSubfolders, ฯลฯ เมธอด แต่ข้อความหรือโฟลเดอร์เดี่ยวอาจยังไม่เสียหายในที่เก็บข้อมูล

เมธอดสำหรับค้นหาตัวระบุรายการ

เมธอดต่อไปนี้ช่วยให้คุณค้นหาตัวระบุของรายการแบบลำดับขั้น

ตัวระบุที่ได้จากการใช้เมธอดเหล่านี้สามารถใช้เพื่อดึงข้อความและโฟลเดอร์ได้

หมายเหตุ: ควรทราบว่าแม้มีข้อดี แต่ยังมีที่เก็บข้อมูลที่เสียหายที่ไม่สามารถอ่านได้แม้ใช้เมธอดเหล่านี้

การสำรวจไฟล์ PST

ตัวอย่างโค้ดต่อไปนี้แสดงการสำรวจไฟล์ PST และสกัดโฟลเดอร์และข้อความ เพื่อรับรายการตัวระบุให้ใช้เมธอด FindMessages และ FindSubfolders จากนั้นตัวระบุจะถูกส่งไปยัง the ExtractMessage หรือ GetFolderById เมธอดสำหรับสกัดเอาองค์ประกอบ

using (var pst = PersonalStorage.FromFile(fileName))
{
    ExploreCorruptedPst(pst, pst.RootFolder.EntryIdString);
}

public static void ExploreCorruptedPst(PersonalStorage pst, string rootFolderId)
{
    var messageIdList = pst.FindMessages(rootFolderId);

    foreach (var messageId in messageIdList)
    {
        try
        {
            var msg = pst.ExtractMessage(messageId);
            Console.WriteLine( "- " + msg.Subject);
        }
        catch
        {
            Console.WriteLine("Message reading error. Entry id: " + messageId);
        }
    }

    var folderIdList = pst.FindSubfolders(rootFolderId);

    foreach (var subFolderId in folderIdList)
    {
        if (subFolderId != rootFolderId)
        {
            try
            {
                FolderInfo subfolder = pst.GetFolderById(subFolderId);
                Console.WriteLine(subfolder.DisplayName);
            }
            catch
            {
                Console.WriteLine("Message reading error. Entry id: " + subFolderId);
            }

            ExplodeCorruptedPst(pst, subFolderId);
        }
    }
}