本文整理汇总了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));
//.........这里部分代码省略.........
示例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);
//.........这里部分代码省略.........