當前位置: 首頁>>代碼示例>>C#>>正文


C# NPOIFSFileSystem.CreateDirectory方法代碼示例

本文整理匯總了C#中NPOI.POIFS.FileSystem.NPOIFSFileSystem.CreateDirectory方法的典型用法代碼示例。如果您正苦於以下問題:C# NPOIFSFileSystem.CreateDirectory方法的具體用法?C# NPOIFSFileSystem.CreateDirectory怎麽用?C# NPOIFSFileSystem.CreateDirectory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在NPOI.POIFS.FileSystem.NPOIFSFileSystem的用法示例。


在下文中一共展示了NPOIFSFileSystem.CreateDirectory方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CreateWriteRead

        public void CreateWriteRead()
        {
            NPOIFSFileSystem fs = new NPOIFSFileSystem();
            DocumentEntry miniDoc;
            DocumentEntry normDoc;

            // Initially has a BAT but not SBAT
            Assert.AreEqual(POIFSConstants.FAT_SECTOR_BLOCK, fs.GetNextBlock(0));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(1));
            Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, fs.GetNextBlock(2));

            // Check that the SBAT is empty
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.Root.Property.StartBlock);

            // Check that no properties table has been written yet
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.PropertyTable.StartBlock);

            // Write and read it
            fs = WriteOutAndReadBack(fs);

            // Property table entries have been added to the blocks 
            Assert.AreEqual(POIFSConstants.FAT_SECTOR_BLOCK, fs.GetNextBlock(0));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(1));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(2));
            Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, fs.GetNextBlock(3));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.Root.Property.StartBlock);
            Assert.AreEqual(2, fs.PropertyTable.StartBlock);

            // Put everything within a new directory
            DirectoryEntry testDir = fs.CreateDirectory("Test Directory");

            // Add a new Normal Stream (Normal Streams minimum 4096 bytes)
            byte[] main4096 = new byte[4096];
            main4096[0] = unchecked((byte)-10);
            main4096[4095] = unchecked((byte)-11);
            testDir.CreateDocument("Normal4096", new MemoryStream(main4096));

            Assert.AreEqual(POIFSConstants.FAT_SECTOR_BLOCK, fs.GetNextBlock(0));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(1));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(2));

            Assert.AreEqual(4, fs.GetNextBlock(3));
            Assert.AreEqual(5, fs.GetNextBlock(4));
            Assert.AreEqual(6, fs.GetNextBlock(5));
            Assert.AreEqual(7, fs.GetNextBlock(6));
            Assert.AreEqual(8, fs.GetNextBlock(7));
            Assert.AreEqual(9, fs.GetNextBlock(8));
            Assert.AreEqual(10, fs.GetNextBlock(9));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(10));
            Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, fs.GetNextBlock(11));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.Root.Property.StartBlock);


            // Add a bigger Normal Stream
            byte[] main5124 = new byte[5124];
            main5124[0] = unchecked((byte)-22);
            main5124[5123] = unchecked((byte)-33);
            testDir.CreateDocument("Normal5124", new MemoryStream(main5124));

            Assert.AreEqual(POIFSConstants.FAT_SECTOR_BLOCK, fs.GetNextBlock(0));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(1));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(2));
                Assert.AreEqual(4, fs.GetNextBlock(3));
                Assert.AreEqual(5, fs.GetNextBlock(4));
                Assert.AreEqual(6, fs.GetNextBlock(5));
                Assert.AreEqual(7, fs.GetNextBlock(6));
                Assert.AreEqual(8, fs.GetNextBlock(7));
                Assert.AreEqual(9, fs.GetNextBlock(8));
                Assert.AreEqual(10, fs.GetNextBlock(9));
                Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(10));

                Assert.AreEqual(12, fs.GetNextBlock(11));
                Assert.AreEqual(13, fs.GetNextBlock(12));
                Assert.AreEqual(14, fs.GetNextBlock(13));
                Assert.AreEqual(15, fs.GetNextBlock(14));
                Assert.AreEqual(16, fs.GetNextBlock(15));
                Assert.AreEqual(17, fs.GetNextBlock(16));
                Assert.AreEqual(18, fs.GetNextBlock(17));
                Assert.AreEqual(19, fs.GetNextBlock(18));
                Assert.AreEqual(20, fs.GetNextBlock(19));
                Assert.AreEqual(21, fs.GetNextBlock(20));
                Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(21));
                Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, fs.GetNextBlock(22));

            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.Root.Property.StartBlock);


            // Now Add a mini stream
            byte[] mini = new byte[] { 42, 0, 1, 2, 3, 4, 42 };
            testDir.CreateDocument("Mini", new MemoryStream(mini));

            // Mini stream will Get one block for fat + one block for data
            Assert.AreEqual(POIFSConstants.FAT_SECTOR_BLOCK, fs.GetNextBlock(0));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(1));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(2));

                Assert.AreEqual(4, fs.GetNextBlock(3));
                Assert.AreEqual(5, fs.GetNextBlock(4));
                Assert.AreEqual(6, fs.GetNextBlock(5));
                Assert.AreEqual(7, fs.GetNextBlock(6));
//.........這裏部分代碼省略.........
開發者ID:Reinakumiko,項目名稱:npoi,代碼行數:101,代碼來源:TestNPOIFSFileSystem.cs

示例2: AddBeforeWrite

        public void AddBeforeWrite()
        {
            NPOIFSFileSystem fs = new NPOIFSFileSystem();
            DocumentEntry miniDoc;
            DocumentEntry normDoc;
            HeaderBlock hdr;

            // Initially has BAT + Properties but nothing else
            Assert.AreEqual(POIFSConstants.FAT_SECTOR_BLOCK, fs.GetNextBlock(0));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(1));
            Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, fs.GetNextBlock(2));

            hdr = WriteOutAndReadHeader(fs);
            // No mini stream, and no xbats
            // Will have fat then properties stream
            Assert.AreEqual(1, hdr.BATCount);
            Assert.AreEqual(0, hdr.BATArray[0]);
            Assert.AreEqual(2, hdr.PropertyStart);
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, hdr.SBATStart);
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, hdr.XBATIndex);
            Assert.AreEqual(POIFSConstants.SMALLER_BIG_BLOCK_SIZE * 4, fs.Size);


            // Get a clean filesystem to start with
            fs = new NPOIFSFileSystem();

            // Put our test files in a non-standard place
            DirectoryEntry parentDir = fs.CreateDirectory("Parent Directory");
            DirectoryEntry testDir = parentDir.CreateDirectory("Test Directory");


            // Add to the mini stream
            byte[] mini = new byte[] { 42, 0, 1, 2, 3, 4, 42 };
            testDir.CreateDocument("Mini", new MemoryStream(mini));

            // Add to the main stream
            byte[] main4096 = new byte[4096];
            main4096[0] = unchecked((byte)-10);
            main4096[4095] = unchecked((byte)-11);
            testDir.CreateDocument("Normal4096", new MemoryStream(main4096));


            // Check the mini stream was Added, then the main stream
            Assert.AreEqual(POIFSConstants.FAT_SECTOR_BLOCK, fs.GetNextBlock(0));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(1));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(2));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(3));
            Assert.AreEqual(5, fs.GetNextBlock(4));
            Assert.AreEqual(6, fs.GetNextBlock(5));
            Assert.AreEqual(7, fs.GetNextBlock(6));
            Assert.AreEqual(8, fs.GetNextBlock(7));
            Assert.AreEqual(9, fs.GetNextBlock(8));
            Assert.AreEqual(10, fs.GetNextBlock(9));
            Assert.AreEqual(11, fs.GetNextBlock(10));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(11));
            Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, fs.GetNextBlock(12));
            Assert.AreEqual(POIFSConstants.SMALLER_BIG_BLOCK_SIZE * 13, fs.Size);

            // Check that we can read the right data pre-write
            miniDoc = (DocumentEntry)testDir.GetEntry("Mini");
            assertContentsMatches(mini, miniDoc);

            normDoc = (DocumentEntry)testDir.GetEntry("Normal4096");
            assertContentsMatches(main4096, normDoc);

            // Write, Read, check
            hdr = WriteOutAndReadHeader(fs);
            fs = WriteOutAndReadBack(fs);

            // Check the header details - will have the sbat near the start,
            //  then the properties at the end
            Assert.AreEqual(1, hdr.BATCount);
            Assert.AreEqual(0, hdr.BATArray[0]);
            Assert.AreEqual(2, hdr.SBATStart);
            Assert.AreEqual(12, hdr.PropertyStart);
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, hdr.XBATIndex);

            // Check the block allocation is unChanged, other than
            //  the properties stream going in at the end
            Assert.AreEqual(POIFSConstants.FAT_SECTOR_BLOCK, fs.GetNextBlock(0));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(1));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(2));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(3));
            Assert.AreEqual(5, fs.GetNextBlock(4));
            Assert.AreEqual(6, fs.GetNextBlock(5));
            Assert.AreEqual(7, fs.GetNextBlock(6));
            Assert.AreEqual(8, fs.GetNextBlock(7));
            Assert.AreEqual(9, fs.GetNextBlock(8));
            Assert.AreEqual(10, fs.GetNextBlock(9));
            Assert.AreEqual(11, fs.GetNextBlock(10));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(11));
            Assert.AreEqual(13, fs.GetNextBlock(12));
            Assert.AreEqual(POIFSConstants.END_OF_CHAIN, fs.GetNextBlock(13));
            Assert.AreEqual(POIFSConstants.UNUSED_BLOCK, fs.GetNextBlock(14));
            Assert.AreEqual(POIFSConstants.SMALLER_BIG_BLOCK_SIZE * 15, fs.Size);
       
            // Check the data
            DirectoryEntry fsRoot = fs.Root;
            Assert.AreEqual(1, fsRoot.EntryCount);

//.........這裏部分代碼省略.........
開發者ID:Reinakumiko,項目名稱:npoi,代碼行數:101,代碼來源:TestNPOIFSFileSystem.cs


注:本文中的NPOI.POIFS.FileSystem.NPOIFSFileSystem.CreateDirectory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。